简体   繁体   中英

How to modify the structure of a production database with symfony 1.4

Problem:

  • I have a symfony project with a database full of production data
  • I want to change its structure (add/drop a table or add/drop/change an existing field)

How do I do that without wiping my database ?

Because when you change your schema.yml, you need to doctrine build --all if you want your changes to take place in the database, and this task wipes out the database, the production database.


Things I tried:

This blog basically says to do the following:

php symfony doctrine:data-dump
php symfony doctrine:build --all
phpsymfony doctrine:data-load data/fixtures/data.yml #default name for fixtures file

But it prints an error about a foreign key constraint. (In my case, I am trying to add a table with a foreign key in an existing one).

Based on the same idea: I tried the following:

mysqldump -u root -p > DBexport.sql
php symfony doctrine:build --all

# open DBexport.sql in a text editor and remove all queries for
# creating the structure of the database
mysql -u root -p shop < DBexport_data.sql

But I have this error:

ERROR 1136 (21S01) at line 34: Column count doesn't match value count at row 1

Because in a table I have added a field and the old database doesn't have the right field count...

I work extensively with multiple symfony projects, one of which is a high traffic enterprise SAS (software as a solution) application, and we have NEVER propagated schema changes from the Symfony side. We actually had a new junior dev accidentally delete data from our dev database by trying make schema changes using Symfony.

My suggestion would be to make the schema changes to the schema manually, then update your data schema file (.yml) to reflect the schema changes, then you can run the following commands to update the model, filter, and forms files:

php symfony doctrine:build-model
php symfony doctrine:build-filters
php symfony doctrine:build-forms
php symfony cc

Be sure you make your changes to your dev environment first, so you can test and make sure the code works. Then when you push your code to the production environment, you can make the schema changes then publish the code. If the schema changes you are making will not break the existing code base, I would make them a day or two in advance of the code-push

我可能对这个问题有误解,但是Migrations是否可以解决您的问题?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM