开发者

Symfony migration failing

I just changed my schema for a symfony project I'm working on (added a table and a few columns) and ran the following two commands:

php symfony doc:generate-migrations-diff
php symfony doc:migrate

Previously this has worked without any problems, but this time it freaked out. I accidently gave two tables the same name, which it reasonably failed on, but now that I fixed my schema file it still won't work. It produces the following errors:

  The following errors occurred:                                                                                                                                                                                                                                                                                           

   - SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'media_images' already exists. Failing Query: "CREATE TABLE media_images (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(255), start_date DATE, end_date DATE, website VARCHAR(255), location TEXT, description TEXT, PRIMARY KEY(id)) ENGINE = INNODB"  
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company_type'. Failing Query: "ALTER TABLE bio ADD company_type VARCHAR(255)"                                                                                                                                                                     
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company'. Failing Query: "ALTER TABLE bio ADD company VARCHAR(255)"                                                                                                                                                                               
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company_type'. Failing Query: "ALTER TABLE bio ADD company_type VARCHAR(255)"                                                                                                                                                                     
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company'. Failing Query: "ALTER TABLE bio ADD company VARCHAR(255)"                                                                                                                                                                               
   - SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'media_events' already exists. Failing Query: "CREATE TABLE media_events (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(255), start_date DATE, end_date DATE, website VARCHAR(255), location TEXT, description TEXT, PRIMARY KEY(id)) ENGINE = INNODB"  
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company_type'. Failing Query: "ALTER TABLE bio ADD company_type VARCHAR(255)"                                                                                                                                                                     
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company'. Failing Query: "ALTER TABLE bio ADD company VARCHAR(255)"                                                                                                                                                                               
   - SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'media_events' already exists. Failing Query: "CREATE TABLE media_events (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(255), start_date DATE, end_date DATE, website VARCHAR(255), location TEXT, description TEXT, PRIMARY KEY(id)) ENGINE = INNODB"  
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company_type'. Failing Query: "ALTER TABLE bio ADD company_type VARCHAR(255)"                                                                                                                                                                     
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company'. Failing Query: "ALTER TABLE bio ADD company VARCHAR(255)"             

Mostly this is confusing because it is reporting the same error multiple t开发者_C百科imes. I have deleted the /tmp/doctrine_schema_[random_number].yml files and tried again, no luck. I also brought up the mysql console and manually deleted the tables and columns it is complaining about but it still generated the same error.

Any ideas?


When things get messed up with migrations, there are a couple of things you might have to do to get back on track, depending on the situation.

If you have a migration class that PARTLY works (going up or down in version) but has errors, then your database's schema is inconsistent between the migration, and it might then fail to go up or down. Then the next time you try to run it you get even more errors because of changes already committed.

You then have to either apply ONLY the missing changes and re-run it until it succeeds. I do that by temporarily commenting out the parts of the migration that have already worked and correcting the problems with those that failed. It can also be done manually via your database's management tools but you run the risk of not exactly configuring things the same way.

Sometimes it's also useful to manually change the value stored in the migration_version table (using a non-Doctrine database tool) to force Doctrine to realize it's at a different version. Then try migrating down and up again.

Also, I highly recommend always testing new migration classes by applying them up, then back down one version and up again. There are bugs in the doctrine:generate-migrations-diff task that especially with foreign keys can create irreversible migrations. I find those need to be hand-edited before running them to be valid in both directions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜