Opened 17 years ago
Closed 16 years ago
#7236 closed (worksforme)
Table containing ForeignKey created with wrong casing
Reported by: | Owned by: | George Vilches | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | mysql case table name lower_case_table_names | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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
Change History (7)
comment:1 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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.
comment:3 by , 17 years ago
Component: | Uncategorized → Database wrapper |
---|
comment:4 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:5 by , 16 years ago
Description: | modified (diff) |
---|---|
Keywords: | mysql case table name lower_case_table_names added |
comment:6 by , 16 years ago
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.
comment:7 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
One month passed, nothing happened: Closed.
Removing this ticket while I enquire in Django users