Updating a schema with doctrine2 postgresql always DROPs and then ADDs CONSTRAINTs

When updating the scheme, the doctrine always falls and adds limitations. I think something is wrong ...

php app/console doctrine:schema:update --force
Updating database schema...
Database schema updated successfully! "112" queries were executed

php app/console doctrine:schema:update --dump-sql
ALTER TABLE table.managers DROP CONSTRAINT FK_677E81B7A76ED395;
ALTER TABLE table.managers ADD CONSTRAINT FK_677E81B7A76ED395 FOREIGN KEY (user_id) REFERENCES table."user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE;
...

php app/console doctrine:schema:validate
[Mapping]  OK - The mapping files are correct.
[Database] FAIL - The database schema is not in sync with the current mapping file.

How can this be fixed?

+4
source share
3 answers

After some digging into the methods of the doctrine update scheme, I finally found a problem. The problem was the table names - "table.order" and "table.user". When doctrine does diff, these names become unequal due to internal escaping (?). Thus, "user"! = User and foreign keys to these tables (order, user) are always recreated.

# 1 - , postgresql, my_user, my_order. №2 - . , .

# 1, :

-

+2

Postgres where.

* @ORM\ (name= "avatar",
 * uniqueConstraints = {
 * @ORM\UniqueConstraint (name= "const_name", columns = { "id_user", "status" }, options = { "where": "(status = 'pending')" })

Doctrine , .

string(34) "((status)::text = 'pending'::text)"
string(20) "(status = 'pending')"

,

((avatar)::text = 'pending'::text)

PS: Postgres

, -.

+1

, , php- - . , .

If you remove the restriction on database and php objects (remove the doctrine2 mappings), refresh the schema and make sure nothing needs to be updated. Then add the doctrine mapping back to php, update the schema with --dump-sql and view the displayed changes. Make sure that this is exactly what you want and complete the update request. Now updating the schema should not show that something else needs to be updated.

0
source

Source: https://habr.com/ru/post/1530394/


All Articles