更改后实体不会更新
Entities aren’t updated after changes
我刚开始使用 Symfony,今天我遇到了一个问题,我无法更改实体的属性:Doctrine 不想将更改插入到我的数据库中...
我正在寻找答案,例如 ,但我没有找到解决方案。
因为我是新手,所以我从一个空白项目再次尝试:
我创建了一个新实体:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:entity
Class name of the entity to create or update (e.g. TinyChef):
> Product
created: src/Entity/Product.php
created: src/Repository/ProductRepository.php
Entity generated! Now let's add some fields!
You can always add more fields later manually or by re-running this command.
New property name (press <return> to stop adding fields):
> name
Field type (enter ? to see all types) [string]:
>
Field length [255]:
>
Can this field be null in the database (nullable) (yes/no) [no]:
>
updated: src/Entity/Product.php
Add another property? Enter the property name (or press <return> to stop adding fields):
>
Success!
Next: When you're ready, create a migration with make:migration
然后我进行迁移:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:migration
Success!
Next: Review the new migration "src/Migrations/Version20191122111110.php"
Then: Run the migration with php bin/console doctrine:migrations:migrate
See https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
我运行它:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console doctrine:migration:migrate
Application Migrations
WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)y
Migrating up to 20191122111110 from 0
++ migrating 20191122111110
-> CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
++ migrated (took 36.5ms, used 16M memory)
------------------------
++ finished in 39ms
++ used 16M memory
++ 1 migrations executed
++ 1 sql queries
并且我向我的实体添加了一个新的 属性:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:entity
Class name of the entity to create or update (e.g. FierceGnome):
> Product
Your entity already exists! So let's add some new fields!
New property name (press <return> to stop adding fields):
> description
Field type (enter ? to see all types) [string]:
>
Field length [255]:
>
Can this field be null in the database (nullable) (yes/no) [no]:
>
updated: src/Entity/Product.php
Add another property? Enter the property name (or press <return> to stop adding fields):
>
Success!
Next: When you're ready, create a migration with make:migration
当我尝试创建迁移时它不起作用:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:migration
[WARNING] No database changes were detected.
The database schema and the application mapping information are already in sync.
有人可以帮助我吗?如果我不明白它是如何工作的或其他什么...
谢谢!
我遇到了同样的问题。清除缓存对我有用。
symfony console cache:clear
我刚开始使用 Symfony,今天我遇到了一个问题,我无法更改实体的属性:Doctrine 不想将更改插入到我的数据库中...
我正在寻找答案,例如
因为我是新手,所以我从一个空白项目再次尝试:
我创建了一个新实体:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:entity
Class name of the entity to create or update (e.g. TinyChef):
> Product
created: src/Entity/Product.php
created: src/Repository/ProductRepository.php
Entity generated! Now let's add some fields!
You can always add more fields later manually or by re-running this command.
New property name (press <return> to stop adding fields):
> name
Field type (enter ? to see all types) [string]:
>
Field length [255]:
>
Can this field be null in the database (nullable) (yes/no) [no]:
>
updated: src/Entity/Product.php
Add another property? Enter the property name (or press <return> to stop adding fields):
>
Success!
Next: When you're ready, create a migration with make:migration
然后我进行迁移:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:migration
Success!
Next: Review the new migration "src/Migrations/Version20191122111110.php"
Then: Run the migration with php bin/console doctrine:migrations:migrate
See https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
我运行它:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console doctrine:migration:migrate
Application Migrations
WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)y
Migrating up to 20191122111110 from 0
++ migrating 20191122111110
-> CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
++ migrated (took 36.5ms, used 16M memory)
------------------------
++ finished in 39ms
++ used 16M memory
++ 1 migrations executed
++ 1 sql queries
并且我向我的实体添加了一个新的 属性:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:entity
Class name of the entity to create or update (e.g. FierceGnome):
> Product
Your entity already exists! So let's add some new fields!
New property name (press <return> to stop adding fields):
> description
Field type (enter ? to see all types) [string]:
>
Field length [255]:
>
Can this field be null in the database (nullable) (yes/no) [no]:
>
updated: src/Entity/Product.php
Add another property? Enter the property name (or press <return> to stop adding fields):
>
Success!
Next: When you're ready, create a migration with make:migration
当我尝试创建迁移时它不起作用:
luc@Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:migration
[WARNING] No database changes were detected.
The database schema and the application mapping information are already in sync.
有人可以帮助我吗?如果我不明白它是如何工作的或其他什么...
谢谢!
我遇到了同样的问题。清除缓存对我有用。
symfony console cache:clear