Opened 17 years ago
Last modified 17 years ago
#7586 closed
contenttypes table not created properly — at Version 1
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Uncategorized | Version: | dev |
| 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 |
Description (last modified by )
if i have 2 applications - app1, app2 , both with a sub-module sub:
app1/sub/models.py app2/sub/models.py
then only models from one of the apps will get a row in the django_contenttypes table.
This is because, when processing app2 - in update_contenttypes (contenttypes/manangement.py) first gets all current contenttypes for app1 (because the query ContentType.objects.filter(app_label=app.__name__.split('.')[-2]) returns all the rows for app1 and app2)
and then after inserting all the objects for app2 (which are not present there) - it deletes all the previous objects inserted for app1 because it thinks they're 'stale' (they weren't part of get_models(app2))
(Fixed description formatting somewhat)
Can you please confirm that you have the
Meta.app_labelattribute set on both these models? And that they are set to different things? If you have models inside subdirectories,app_labelmust be set, otherwise Django cannot work out theapp_namecorrectly. It sounds like the only reasons that models from both applications are being pulled back is because Django thinks their app names aresub(when they should beapp1andapp2).