Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#8659 closed (invalid)

Quote relation name creating PostgreSQL database

Reported by: Hystrix Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Using PostgreSQL as a database backend, if I define a model with a foreignkey field with an uppercase letter in the attribute name, the relation constrait name would end with all the letters in lowercase. This can have various side effects such as not being able to reset the database becuase Django can't remove the constrait (it tries to remove a constrait with uppercase letters and the one in the database is all lowercase).
This happens because the constraint name is not quoted when the database is created.
All it takes to fix this is add backend.quote_name to the name while creating the sql.
I fixed it in 0.96 but I can't find where this should be changed in SVN.

Bad SQL:
ALTER TABLE "proto0_viaje" ADD CONSTRAINT reservadoPor_id_refs_id_331c0818 FOREIGN KEY ("reservadoPor_id") REFERENCES "proto0_empleado" ("id") DEFERRABLE INITIALLY DEFERRED;

Good SQL:
ALTER TABLE "proto0_viaje" ADD CONSTRAINT "reservadoPor_id_refs_id_331c0818" FOREIGN KEY ("reservadoPor_id") REFERENCES "proto0_empleado" ("id") DEFERRABLE INITIALLY DEFERRED;

Change History (4)

comment:1 Changed 6 years ago by jacob

  • milestone set to 1.1
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by mtredinnick

  • Component changed from Core framework to Database layer (models, ORM)

comment:3 Changed 6 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

This looks like a bit of a non-issue. Constraint names already are quoted in both trunk and 1.0.X.

The code in question is in django/db/backends/creation.py (plus possible db-specific extensions, but PostgreSQL uses the default).

comment:4 Changed 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top