<tfoot id='FVDUm'></tfoot>

      <i id='FVDUm'><tr id='FVDUm'><dt id='FVDUm'><q id='FVDUm'><span id='FVDUm'><b id='FVDUm'><form id='FVDUm'><ins id='FVDUm'></ins><ul id='FVDUm'></ul><sub id='FVDUm'></sub></form><legend id='FVDUm'></legend><bdo id='FVDUm'><pre id='FVDUm'><center id='FVDUm'></center></pre></bdo></b><th id='FVDUm'></th></span></q></dt></tr></i><div id='FVDUm'><tfoot id='FVDUm'></tfoot><dl id='FVDUm'><fieldset id='FVDUm'></fieldset></dl></div>
      • <bdo id='FVDUm'></bdo><ul id='FVDUm'></ul>

    1. <small id='FVDUm'></small><noframes id='FVDUm'>

      <legend id='FVDUm'><style id='FVDUm'><dir id='FVDUm'><q id='FVDUm'></q></dir></style></legend>

      向 Symfony 中的现有实体添加一列

      Add a column to an existing entity in Symfony(向 Symfony 中的现有实体添加一列)

            <tfoot id='yorUw'></tfoot>
              <tbody id='yorUw'></tbody>

            • <bdo id='yorUw'></bdo><ul id='yorUw'></ul>
              1. <legend id='yorUw'><style id='yorUw'><dir id='yorUw'><q id='yorUw'></q></dir></style></legend>

                <small id='yorUw'></small><noframes id='yorUw'>

                <i id='yorUw'><tr id='yorUw'><dt id='yorUw'><q id='yorUw'><span id='yorUw'><b id='yorUw'><form id='yorUw'><ins id='yorUw'></ins><ul id='yorUw'></ul><sub id='yorUw'></sub></form><legend id='yorUw'></legend><bdo id='yorUw'><pre id='yorUw'><center id='yorUw'></center></pre></bdo></b><th id='yorUw'></th></span></q></dt></tr></i><div id='yorUw'><tfoot id='yorUw'></tfoot><dl id='yorUw'><fieldset id='yorUw'></fieldset></dl></div>
                本文介绍了向 Symfony 中的现有实体添加一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我一直在我的 web 服务器上玩弄 Symfony,我一直在为我的数据库创建带有学说的实体.我想向这些实体之一添加一列......我想做这样的事情:

                I've been playing around with Symfony on my web server and I've been creating entity with doctrine for my database. I wanted to add a column to one of these entity... I wanted to do something like:

                php app/console doctrine:modify:entity
                

                现在我知道这个命令不存在,但是有没有一种方法(无需进行整个迁移)来简单地添加一列.

                Now I know that this command doesn't exists, but is there a way (without doing a whole migration) to simply add a column.

                附言我知道我可以打开 php 文件并在那里以文本方式添加列,然后更新架构,但我将其分发给一些客户端,我喜欢更类似命令行"的方法.

                P.S. I know I could open the php file and textually add the column there and then update the schema, but I'm distributing this to some clients and I like a more "command-line-like" approach.

                推荐答案

                实际上,使用 Doctrine 来做你建议的事情根本没有意义.

                Actually, using Doctrine does not make sense at all to do something like you suggested.

                Doctrine 是一个 ORM(对象关系映射)工具.这意味着您想从 PHP 代码中抽象出数据库,将数据库的内容委托给 Doctrine.Doctrine 在这方面做得很好.

                Doctrine is a ORM (Object-Relational Mapping) tool. It means that you want to abstract the database from your PHP code, you delegate database stuff to Doctrine. Doctrine does a wonderful job on that area.

                因为你想让你的客户/同行更新模型的最新版本,你应该使用 Doctrine Migrations ( http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html).这就是管理数据库更新的方式.此外,它使您可以完全控制升级/降级数据库时要执行的操作.例如,您可以在添加 FK 之前设置默认值.

                As you want to keep your customers/peers updated with the latest version of the model, you should use the Doctrine Migrations ( http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html ). That's the way to manage database updates. Moreover, it gives you complete control on what to do when upgrading/downgrading the database. You could, e.g., set default values before you add the FK.

                在类上添加新属性的步骤应该是:

                The steps for adding a new property on the class should be:

                对于 Symfony 2:

                • 通过以下方式修改类:

                • modify the class by:

                • AcmeMyBundleEntityCustomer 并添加你想要的属性;

                • AcmeMyBundleEntityCustomer and add the property you want;

                AcmeMyBundleEntityCustomer

                或修改学说文件:

                Acme/MyBundle/Resources/config/doctrine/customer.yml

                运行控制台命令(它将在类中添加正确的设置/获取)

                run the console command (it will add the proper set/get in the class)

                php 应用/控制台学说:生成:实体 AcmeMyBundle:客户

                运行控制台命令

                php 应用程序/控制台原则:迁移:差异

                运行控制台命令(它将在 app/DoctrineMigrations 上放置一个新文件)

                run the console command (it will place a new file on app/DoctrineMigrations)

                php 应用程序/控制台准则:迁移:迁移

                在部署新版本的代码时,您所要做的就是更新源代码并运行上面的命令.

                When you're deploying the new version of the code, all you got to do is update the source code and run the command above.

                对于 Symfony 3:

                • 通过以下方式修改类:

                • modify the class by:

                • AcmeMyBundleEntityCustomer 并添加你想要的属性;

                • AcmeMyBundleEntityCustomer and add the property you want;

                AcmeMyBundleEntityCustomer

                或修改学说文件:

                Acme/MyBundle/Resources/config/doctrine/customer.yml

                运行控制台命令(它将在类中添加正确的设置/获取)

                run the console command (it will add the proper set/get in the class)

                php bin/console science:generate:entities AcmeMyBundle:Customer

                运行控制台命令(更新数据库)

                run the console command (update database)

                php bin/console algorithm:schema:update --force

                这篇关于向 Symfony 中的现有实体添加一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                How to parse django style template tags(如何解析 django 样式模板标签)
                What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                php in background exec() function(php 后台 exec() 函数)

                • <bdo id='xEKH3'></bdo><ul id='xEKH3'></ul>
                  • <tfoot id='xEKH3'></tfoot>
                    <i id='xEKH3'><tr id='xEKH3'><dt id='xEKH3'><q id='xEKH3'><span id='xEKH3'><b id='xEKH3'><form id='xEKH3'><ins id='xEKH3'></ins><ul id='xEKH3'></ul><sub id='xEKH3'></sub></form><legend id='xEKH3'></legend><bdo id='xEKH3'><pre id='xEKH3'><center id='xEKH3'></center></pre></bdo></b><th id='xEKH3'></th></span></q></dt></tr></i><div id='xEKH3'><tfoot id='xEKH3'></tfoot><dl id='xEKH3'><fieldset id='xEKH3'></fieldset></dl></div>

                          <tbody id='xEKH3'></tbody>

                        1. <small id='xEKH3'></small><noframes id='xEKH3'>

                        2. <legend id='xEKH3'><style id='xEKH3'><dir id='xEKH3'><q id='xEKH3'></q></dir></style></legend>