如何使用 Doctrine 从模型中删除和重建表而不丢失数据?
我使用以下代码从我的模型构建表:
Doctrine::createTablesFromModels();
我刚刚开始一个新项目,这是我第一次在应用程序中使用 Doctrine。到目前为止,由于我刚刚开始并且没有任何数据,因此我只是将表删除到 phpMyAdmin 中,并在每次更改模型时运行上面的代码。显然,这在生产环境中不是一个选择。
Doctrine 是否有一个或多个我可以调用的方法来删除和重建表而不丢失现有数据?也许首先将其保存到一些临时表中?如果没有,我还有什么其他选择来完成同样的事情?
或者,我让 Doctrine 生成表格的方向是否完全错误?我是否应该自己维护它们并使我的模型中的关系和专栏保持最新状态?
我将 Doctrine 1.2 与 CodeIgniter 框架结合使用。
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 rebuild 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 Doctrine Migrations,这是编写模型/模式版本之间的更改脚本的方法。
http://www.doctrine-project.org/projects /orm/1.2/docs/manual/migrations/en
就我个人而言,我只是对我的架构进行更改,然后从中生成模型。
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.
我正在使用 Doctrine2,这是我过去所做的:
注意::如果您定义了触发器,这可能会变得很棘手。对于生产站点来说也不是一个好主意,除非出现“停机维护”类型的情况。
请参阅 插入选择
I am using Doctrine2, here's what I've done in the past:
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