Opened 10 years ago

Closed 10 years ago

#13318 closed (worksforme)

Django messed up the table names.

Reported by: songziang@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I am working on a project which contains multiple tables in model. I named on table Users with the meta setup to be 'Users'. However, the table was created in mysql is "Users" rather than "users". There are also some tables' names contains upper case characters. Event mysql is case-insensitive, it still causes foreign key creation failure.

When I change all meta table name to lowercase, everything works.

So I guess there must be something wrong with the parser of the model in the current django release.

Change History (1)

comment:1 Changed 10 years ago by Russell Keith-Magee

Resolution: worksforme
Status: newclosed

Under my testing, if you have the following models:

class Bar(models.Model):
    class Meta:
        db_table = 'Bar'

class Foo(models.Model):
    bar = models.ForeignKey(Bar)
    `id` integer NOT NULL PRIMARY KEY
CREATE TABLE `myapp_foo` (
    `bar_id` varchar(10) NOT NULL
ALTER TABLE `myapp_foo` ADD CONSTRAINT `bar_id_refs_id_34b02b8` FOREIGN KEY (`bar_id`) REFERENCES `Bar` (`id`);

This has capitals where capitals are needed, and quoting where quoting is needed to preserve those capitals. As far as I can make out this is completely correct.

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