Rebuild model without loss data in MySQL for Symfony

这一生的挚爱 提交于 2019-12-21 20:22:38

问题


What is the best way to rebuild a model without loss data in MySQL for Symfony?

What if I have a big site, and a lot of data in the database and I would like after six months to add few new fields to database?


回答1:


You can use migration.

Doctine manual

Symfony task for migrations

Slideshare presentation

Slideshare presentation

So you need write migrations, migrate, and build your models, forms, etc.




回答2:


I suggest you use @denys281 for Symfony1.4 ....in Symfony2 however its VERY simple ... just use the command :

php app/console doctrine:schema:update --force

It compares what your database should look like (based on the mapping information of your entities) with how it actually looks, and generates the SQL statements needed to update the database to where it should be. In other words, if you add a new property with mapping metadata to Product and run this task again, it will generate the "alter table" statement needed to add that new column to the existing product table. So it doesnt remove any data

There is also a DoctrineMigrations bundle for Symfony2 if you fancy that route -> http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html



来源:https://stackoverflow.com/questions/8138667/rebuild-model-without-loss-data-in-mysql-for-symfony

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!