2

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.

Asis
  • 319
  • 1
  • 2
  • 14
  • Is [mark_migrated](https://book.cakephp.org/migrations/3/en/index.html#mark-migrated-marking-a-migration-as-migrated) what you're looking for? – Greg Schmidt Sep 30 '22 at 13:02
  • @GregSchmidt I'm using phinx standalone, the command you mentioned seems to be part of cakephp/migrations not robmorgan/phinx. – Asis Sep 30 '22 at 13:14
  • My understanding is that Rob was no longer able to support it, so CakePHP took over the maintenance, but the latest version is still able to be used as a standalone project if you need it that way. – Greg Schmidt Sep 30 '22 at 17:57

1 Answers1

1

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

khartnett
  • 831
  • 4
  • 14
  • Yup this does work, I do have to add a check to all initial table migrations, but I don't see any better way. – Asis Sep 30 '22 at 14:37