Home > OS >  Phinx migration SQLSTATE[42S01]: Base table or view already exists:
Phinx migration SQLSTATE[42S01]: Base table or view already exists:

Time:09-30

I want to use Phinx to manage my database. I already have a database with tables setup, so I wrote migrations to reflect what is already in place. Testing from an empty database everything works well, but on the populated database I get the SQLSTATE[42S01]: Base table or view already exists: error.

Is there a command or configuration that will tell Phinx to populate the phinxlog table as if the migration had been previously run? Please note that the tables in prod have data so dropping the tables in any fashion will not work.

CodePudding user response:

In your initial up migrations, you can check if the table already exists: https://book.cakephp.org/phinx/0/en/migrations.html#determining-whether-a-table-exists just flip the logic to if (!$exists). This assumes the existing table matches your migrations, but it sounds like you've checked that and it should populate the phinxlog table.

If any of your new migrations include new columns instead of just new tables you can also check if columns exist with https://book.cakephp.org/phinx/0/en/migrations.html#checking-whether-a-column-exists

  • Related