How to drop and rebuild tables from models without losing data using Doctrine?
I use the following code to build my tables from my models:
Doctrine::createTablesFromModels();
I'm just starting out on a new project and it is the first time I've used Doctrine in an application. So far, since I'm just getting started and don't have any data, I've just been dropping the tables in phpMyAdmin and running the code above every time I make a change to my models. Obviously, this won't be an option in a production environment.
Does Doctrine have a method or chunk of methods I can call that will drop and rebu开发者_如何学Goild the tables without losing the existing data? Perhaps by saving it off to some temporary tables first? If not, what are my other options for accomplishing the same thing?
Or, am I going the totally wrong direction in letting Doctrine generate my tables? Should I just maintain them myself and keep my relationships and columns up to date in my models?
I'm using Doctrine 1.2 with the CodeIgniter framework.
Look into Doctrine Migrations, which are ways to script the changes between versions of your models/schema.
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/migrations/en
Personally, I just make the changes to my schema then generate models from that.
I am using Doctrine2, here's what I've done in the past:
- Rename the table to tablename_BAK
- Create the new tables with doctrine
- Do an INSERT SELECT statement to move your data into the table.
Note:: this could get hairy if you have triggers defined. Also is not a good idea for a production site unless its "Down for maintenance" type of situation.
see INSERT SELECT
精彩评论