Code

Opened 4 years ago

Closed 4 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: UI/UX:

Description

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.

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

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)
CREATE TABLE `Bar` (
    `id` integer NOT NULL PRIMARY KEY
)
;
CREATE TABLE `myapp_foo` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.