bytejunkie bytejunkie - 14 days ago 5
Python Question

django on a vps - getting "model is already registered" when restarting server

asked this question over the weekend, but for some reason all replies have died. started it again as i now have new information

when i restart apache on my vps, i get

the model "category" is already registered


from init.py

i think this is because the object is getting discovered and registered twice.

i didn't think this would be an issue, it isn't in dev where i don't get these errors. also, i dont get the error the first time i run the server after a syncdb.

so upload code, syncdb, start apache, no error message. restart apache and the error message appears.

i can hide it, by commenting out the line that registers the model, but this means that the object doesn't appear in admin unless i uncomment the line and upload it after the admin site has loaded the first time.

this only appears to happen the first time after an apache reset, doesn't happen subsequent times.

anyone come across this before? using apache with mod_wsgi on debian, django 1.2.3

Answer

The error message suggests that model registration code is being repeated. Are you registering your models in the models.py file? The recommended way is to write a separate admin.py file to register the models.