Django

Code

Ticket #7236 (closed: worksforme)

Opened 5 months ago

Last modified 3 months ago

Table containing ForeignKey created with wrong casing

Reported by: narendra.tumkur@gmail.com Assigned to: gav
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: mysql case table name lower_case_table_names
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by ramiro)

Here is the models.py:

class Plugin(models.Model):
	name = models.CharField(max_length=50)
	description = models.CharField(max_length=100)

class PluginContainer(models.Model):
	title = models.CharField(max_length=50)
	plugin_settings = models.CharField(max_length=2000)
	plugin = models.ForeignKey(Plugin)

PluginContainer? refers to Plugin object (ForeignKey?) Running manage.py syncdb produces the tables:

App_plugin
app_plugincontainer

notice the incorrect casing on app_plugincontainer. Removing the ForeignKey? from PluginContainer? correctly creates the table as App_plugincontainer

This is causing a problem with running manage.py syncdb again as it cannot find App_plugincontainer and then tries to create app_plugincontainer and fails as the table already exists.

My environment: OS: Mac OS X 10.5 DB: MySql? 5.05 Python: 2.5 Django: SVN

MySql?'s lower_case_table_names variable is set to 2 (default on mac os x)

Cheers Naren

Attachments

Change History

05/14/08 18:53:01 changed by Narendra Tumkur <narendra.tumkur@gmail.com>

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to invalid.
  • needs_tests changed.
  • needs_docs changed.

Removing this ticket while I enquire in Django users

05/15/08 04:09:29 changed by Narendra Tumkur <narendra.tumkur@gmail.com>

  • status changed from closed to reopened.
  • resolution deleted.

Unable to get any response on user groups. Added some debug statements to syncdb.py and found that the SQL statement being executed did indeed have the correct casing for the table name. However, once again, this problem happens ONLY when the model has a foreign key field. This leads me to believe this is in fact a bug within django and not MySQLdb.

05/15/08 04:51:55 changed by Narendra Tumkur <narendra.tumkur@gmail.com>

  • component changed from Uncategorized to Database wrapper.

06/10/08 11:16:21 changed by gav

  • owner changed from nobody to gav.
  • status changed from reopened to new.

06/16/08 11:07:04 changed by ramiro

  • keywords set to mysql case table name lower_case_table_names.
  • description changed.

06/22/08 23:22:31 changed by gav

I have been unable to validate any part of this ticket's request. I have created an example as follows, with an app of the name "MonkeyTest?", capitalized just as seen here.

#models.py contents
class Plugin(models.Model):
    name = models.CharField(max_length=50)
    description = models.CharField(max_length=100)


class PluginContainer(models.Model):
    title = models.CharField(max_length=50)
    plugin_settings = models.CharField(max_length=2000)
    plugin = models.ForeignKey(Plugin)

The results of python manage.py sql appear correct:

BEGIN;
CREATE TABLE `MonkeyTest_plugin` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` varchar(50) NOT NULL,
    `description` varchar(100) NOT NULL
)
;
CREATE TABLE `MonkeyTest_plugincontainer` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `title` varchar(50) NOT NULL,
    `plugin_settings` varchar(2000) NOT NULL,
    `plugin_id` integer NOT NULL
)
;
ALTER TABLE `MonkeyTest_plugincontainer` ADD CONSTRAINT plugin_id_refs_id_4efbf983 FOREIGN KEY (`plugin_id`) REFERENCES `MonkeyTest_plugin` (`id`);
COMMIT;

And a few tests of filtering all generate the correct queries with the right table name:

Plugin.objects.filter(id=1) generates:

SELECT `MonkeyTest_plugin`.`id`, `MonkeyTest_plugin`.`name`, `MonkeyTest_plugin`.`description` FROM `MonkeyTest_plugin` WHERE `MonkeyTest_plugin`.`id` = 1

PluginContainer.objects.select_related().filter(id=1) generates:

SELECT `MonkeyTest_plugincontainer`.`id`, `MonkeyTest_plugincontainer`.`title`, `MonkeyTest_plugincontainer`.`plugin_settings`,
 `MonkeyTest_plugincontainer`.`plugin_id`, `MonkeyTest_plugin`.`id`, `MonkeyTest_plugin`.`name`, `MonkeyTest_plugin`.`description`
 FROM `MonkeyTest_plugincontainer` 
INNER JOIN `MonkeyTest_plugin` ON (`MonkeyTest_plugincontainer`.`plugin_id` = `MonkeyTest_plugin`.`id`) 
WHERE `MonkeyTest_plugincontainer`.`id` = 1

If you can demonstrate an action that can actually cause this problem, please post it here, including the SQL statements generated from your database of choice. Otherwise, I am recommending this ticket for closing.

07/22/08 09:49:35 changed by julianb

  • status changed from new to closed.
  • resolution set to worksforme.

One month passed, nothing happened: Closed.


Add/Change #7236 (Table containing ForeignKey created with wrong casing)




Change Properties
Action