Opened 11 years ago
Closed 11 years ago
#23988 closed Bug (invalid)
Fixtures should be loaded after migrations
| Reported by: | Yurii Zolot'ko | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | 1.7 |
| Severity: | Normal | 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
It is currently not possible to add data for apps that have migrations in fixtures/initial_data.json because migrate command loads fixtures after syncdb but before migrations i.e. when required tables do not exist yet.
For example if one adds data for flatpages app in fixtures/initial_data like this:
{
"fields": {
"registration_required": false,
"title": "foo",
"url": "/url/",
"template_name": "",
"sites": [1],
"content": "bar",
"enable_comments": false
},
"model": "flatpages.flatpage",
"pk": 1
}
running "manage.py migrate" on new DB will result in:
return Database.Cursor.execute(self, query, params) django.db.utils.OperationalError: Problem installing fixture '/home/user/project/fixtures/initial_data.json': Could not load flatpages.FlatPage(pk=1): no such table: django_flatpage
This breaks DB creation on "manage.py test" as well.
Correct behaviour would be to install initial_data.json AFTER tables for apps with migrations are created as well.
Initial data isn't supported for apps with migrations, see https://docs.djangoproject.com/en/1.7/howto/initial-data/#automatically-loading-initial-data-fixtures.