Phinx: Phinx execute migrate ok, but not create tables

Created on 28 Aug 2017  路  6Comments  路  Source: cakephp/phinx

bug

Most helpful comment

Just to add something that I have noticed that may or may not be the cause of others issues. I had the same problem so I just dropped the database and started over.

I remembered that I ran phinx migrate once without the ->create() method initially, then added the ->create() method, however, every time I ran phinx migrate subsequently no tables were created except the phinxlog.

So after I dropped the database and recreated it I then tested to see if that was the issue and for me it was. If I left out the ->create() method, ran phinx migrate, add the->create() method, and then ran phinx migrate again, then no migration happened.

For me the bug seems to be that you cannot leave out the ->create() method or you will have issues migrating subsequently.

All 6 comments

Wanna put your code here?

But my bet is that you don't call updated(), create() or save()
It should looks like this:

$this->table('tbl')
    ->addColumn(...)
    ->addColumn(...)
    ->addColumn(...)
    ->addIndex(...)
    // this is the method that actually execute the query
    ->create()

Follow the procedures I've done

  1. vendor/bin/phinx init (generate file phinx.yml and configure environment development with database MySQL)
  2. create directory migrations and seed root project
    /project
    db
    migrations
    seeds
  3. create migration vendor/bin/phinx create NomeTabela
    generou template file and add
public function up()
{ 
    $users = $this->table('teste'); 
    $users->addColumn('nome', 'string', array('limit' => 100)) 
          ->addColumn('sobrenome', 'string', array('limit' => 100)) 
          ->addColumn('email', 'string', array('limit' => 100)) 
          ->addColumn('created', 'datetime') 
          ->addColumn('updated', 'datetime', array('null' => true)) 
          ->save(); 
} 
  1. Execute command \vendor\bin\phinx migrate -e development
    generate output
    == 20170829133353 MinhaMigrations: migrating == 20170829133353 MinhaMigrations: migrated 0.0625s

When checking in the database, just created the phinxlog table, but did not create the table corresponding to the migration.

What I did wrong ?

@rmsaitam Out of interest, do you get any different behaviour if you use ->create() instead of ->save()?

I just ran into this issue, when attempting to create a table with an invalid default value:

$table = $this->table('example');
$table->addColumn('exampledate', 'date', array('default' => '0000-00-00' ) )
        ->create();

Migrations appear to run successfully when running vendor/bin/phinx migrate, but the table is not created.

Just to add something that I have noticed that may or may not be the cause of others issues. I had the same problem so I just dropped the database and started over.

I remembered that I ran phinx migrate once without the ->create() method initially, then added the ->create() method, however, every time I ran phinx migrate subsequently no tables were created except the phinxlog.

So after I dropped the database and recreated it I then tested to see if that was the issue and for me it was. If I left out the ->create() method, ran phinx migrate, add the->create() method, and then ran phinx migrate again, then no migration happened.

For me the bug seems to be that you cannot leave out the ->create() method or you will have issues migrating subsequently.

I believe this is fixed in the new release, but please reopen if you still see the error

Was this page helpful?
0 / 5 - 0 ratings