Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10337 closed (invalid)

syncdb fails to load initial_data with certain

Reported by: Torsten 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: no UI/UX: no


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 11 years ago by Russell Keith-Magee

Resolution: worksforme
Status: newclosed

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 11 years ago by Alex Gaynor

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 11 years ago by Torsten Bronger

Resolution: worksforme
Status: closedreopened

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 11 years ago by Alex Gaynor

Resolution: invalid
Status: reopenedclosed

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 11 years ago by Torsten 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