Benjamin Crouzier
Benjamin Crouzier

Reputation: 41865

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

Problem:

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

Upvotes: 0

Views: 2907

Answers (2)

Colin Fine
Colin Fine

Reputation: 3364

I may be misunderstanding the question, but won't Migrations solve your problem?

Upvotes: 1

Mike Purcell
Mike Purcell

Reputation: 19979

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

Upvotes: 2

Related Questions