Ticket #315 (closed defect: fixed)

Opened 5 years ago

Last modified 2 years ago

south appears to lower-case table name when generating constraint for foreign keys

Reported by: abli@… Owned by: andrew
Priority: major Milestone: 0.7
Component: migrations Version: 0.6.2
Keywords: Cc:

Description

South (or django) appears to preserve case when generating tablenames, but forces lower-case when generating 'alter table' statement for add foreign key constraints. This causes the db to refuse adding the foreign key constraint, since it refers to a non-existingtable.

I am using MySql?.

Models.py: (in an app named 'CVtagger')

class Article(models.Model):
    url = models.URLField(unique=True)
    text = models.TextField()
    date = models.DateTimeField(null=True, blank=True)
    marked_up_text = models.TextField(null=True, blank=True)
    annotations = models.TextField(null=True, blank=True)

EntryTypes = (
    ('01', 'foo'),
    ('02', 'bar'),
)
class CVEntry(models.Model):
    article = models.ForeignKey(Article)
    type = models.CharField(max_length=2, choices = EntryTypes)
    company = models.CharField(max_length=255, null=True, blank=True)
    position = models.CharField(max_length=255, null=True, blank=True)
    start_date = models.CharField(max_length=255, null=True, blank=True)
    end_date = models.CharField(max_length=255, null=True, blank=True,)

generating an initial migration for this (with --auto) works fine, but when I try to run that migration (on a mysql db), south appears to try to apply the following sql (at least this is what it prints using --verbosity=2):

CREATE TABLE `CVtagger_cventry` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `article_id` integer NOT NULL, `type` varchar(2) NOT NULL, `company` varchar(255) NULL, `position` varchar(255) NULL, `start_date` varchar(255) NULL, `end_date` varchar(255) NULL);
CREATE TABLE `CVtagger_article` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `url` varchar(200) NOT NULL UNIQUE, `text` longtext NOT NULL, `date` datetime NULL, `marked_up_text` longtext NULL, `annotations` longtext NULL);
ALTER TABLE `CVtagger_cventry` ADD CONSTRAINT `article_id_refs_id_69f0b3bbcdc41ecc` FOREIGN KEY (`article_id`) REFERENCES `cvtagger_article` (`id`);

Note the lower-case 'cvtagger_article' near the end of the 'ALTER TABLE' line.

I am using bleeding-edge hg trunk.
(btw, which version of south is recommended for production use? I can't use 0.6.2 as http://bitbucket.org/andrewgodwin/south/changeset/0db9db159605/ is missing from it, trunk I assume breaks often, and stableish currently appears to mean the same as 0.6.2)

Change History

comment:1 Changed 5 years ago by anonymous

What version/revision of Djang are you using?

comment:2 Changed 5 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.7

Ironically, the very commit you want to use is the one which is making this bug occur! I'll have to work out how to resolve both issues.

comment:3 Changed 5 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed

Alright, the 0.7 branch has this all straightened out in [1e6d1da2d3cc].

comment:4 Changed 2 years ago by aminer@…

My team is using version 0.7.5, and it appears as though this bug is back again :-( We're running a simple migration to add a boolean column to a table and have found that it renames the table to be all lower case.

comment:5 Changed 2 years ago by andrew

In that case, please open a new bug - it'll be a different problem in the code, and so it warrants a new ticket. Remember to upgrade to 0.7.6 first and test it there, and include the migration, the models it's generated from, and the output when you run the migrate command with -v2.

comment:6 Changed 2 years ago by aminer@…

Will do. Thanks, Andrew!

comment:7 Changed 2 years ago by mahmud@…

Hi Andrew,

I have posted a new bug with the problem outlined. I have upgraded to 0.7.6 and I've included the migration that's causing the issue.

http://south.aeracode.org/ticket/1162

Please let me know if you need anything else. This issue is effectively blocking us from using South in production, but I'm very anxious to use it when we get the kinks worked out! Thanks!

Note: See TracTickets for help on using tickets.