更新Symfony 4中的实体? [英] Update an entity in Symfony 4?

查看:141
本文介绍了更新Symfony 4中的实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,但是我找不到很好的答案,我有一个通过命令行创建的实体:

My question is simple, but I can't find a fine answer to it, I had an entity created by a command line :


php bin / console make:entity

php bin/console make:entity

此实体是属性很少的用户(名称-电子邮件-密码)

this entity is User that has few attribute ( name - email - password )

插入字段之后,我进行了迁移,因此已经使用以下命令行在数据库中创建了我的表:

After inserting the fields, I migrated, so my table has been created in the database using those commandlines :


php bin / console make:migration

php bin/console make:migration

php bin /控制台学说:migration:migrate

php bin/console doctrine:migration:migrate

但是现在我只想更改名称用户名,但我不知道该怎么做。

But now I want to just change the name to a username but I don't know how to do it.

我在文档中没有找到任何内容,因此,我们将不胜感激。

I did not find anything in the documentation, so any help would be much appreciated.

推荐答案

请注意:对实体进行任何更改后,必须生成新的迁移文件。实际上,此文件包含必须在数据库上进行的所有更改才能进行更新。
要生成此文件(新的迁移版本),您可以按照以下命令进行操作:

Be careful: After any changes in your entities you must generate new migration file. In fact this file contains all of the changes which must be done on your database to be update. To generate this file (new migration version) you can follow these commands:

$ bin/console doctrine:cache:clear-metadata
$ bin/console doctrine:migrations:diff

在执行上述命令后成功生成了新版本文件,现在,如果运行以下命令,您会看到您有一个新的未执行版本文件:

After above commands you generated your new version file successfully, now if you run following command, you can see you have a new and not executed version file:

$ bin/console doctrine:migrations:status

最后,执行新版本文件并更新数据库,您必须运行以下命令:

Finally, to execute the new version file and update your database, you must run the following command:

$ bin/console doctrine:migrations:migrate --all-or-nothing

现在您的数据库已更新,并且在表中migration_versions 您会看到已添加新版本。

now your database is update and in the table migration_versions you can see that new version has been added.

要成功。

这篇关于更新Symfony 4中的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆