Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#10337 closed (invalid)

syncdb fails to load initial_data with certain

Reported by: bronger Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Keywords:
Cc: bronger@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If the application's contains

from django.contrib.auth import models

" syncdb" doesn't load the init_data fixture for this application.

import django.contrib.auth.models

doesn't cause this problem.

Change History (5)

comment:1 Changed 7 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

I can't replicate this problem. I can't even think of a way that I _could_ replicate this problem - there isn't anything that should link the import method to initial_data fixtures.

If you can provide a complete set of instructions (or preferably, a full project definition) that demonstrates the problem, please reopen.

comment:2 Changed 7 years ago by Alex

I can see why that would break something, but it's not something wrong with django, in python's import process when it sees from module import something the first place it checks is if that item exists in module/, this isn't something Django could fix or work around or anything like that, it's just how python works.

comment:3 Changed 7 years ago by bronger

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I can reproduce it with the following steps:

  1. startproject myproject
  2. ./ startapp myapp
  3. Add a fixture called initial_data which e.g. simply adds a user in myapp/fixtures/
  4. set the database settings in and add "myproject.myapp" to INSTALLED_APPS
  5. create the database in the database backend
  6. call syncdb. The fixture is loaded.
  7. Add myapp/ with the above mentioned line
  8. drop&create the database in the database backend
  9. call syncdb. The fixture is not loaded.

As to what Alex said, sorry but I don't understand it. Be that as it may, I don't see why a high-level functionality like fixture loading depends on how a module is loaded. Currently it does, but it needn't.

comment:4 Changed 7 years ago by Alex

  • Resolution set to invalid
  • Status changed from reopened to closed

When python tries to import the models from your application so that it can instantiate them for the initial_data it's import includes the models path(obviously) however python import semantics say to look in the init of the app for the models name, therefore it can't ever find your applications models since it gets the models name from init which doesn't contain your models.

comment:5 Changed 7 years ago by bronger

Granted, but my application doesn't have models of its own anyway. myapp/ is deliberately empty. Instead, the fixture adds "User" instances from the auth module.

In other words, why does Django assume that a fixture only adds instances of the app's models? For example, User instances can be a very sensible thing to add.

Note: See TracTickets for help on using tickets.
Back to Top