dou29106 2011-05-13 15:56
浏览 64
已采纳

Symfony迁移失败

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 times. 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?

  • 写回答

1条回答 默认 最新

  • duanfu3390 2011-05-13 18:06
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 网友们我该怎么办啊,急
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 目标跟踪,计算机视觉
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败