Django not creating db tables for models (neither with syncdb nor South)

别等时光非礼了梦想. 提交于 2019-11-29 15:02:44

Run the following commands

python manage.py makemigrations yourappname

python manage.py migrate

Note it works on django 1.7 version for me.

you're misunderstanding the process of working with south. South isn't just another application, it's a managing tool. Your app needs to be a South application from the begining or converted to one. That being said, the process is like so:

  1. Add South to INSTALLED_APPS
  2. run syncdb for the first time
  3. Add your app to INSTALLED_APPS*
  4. run the south initialization command:

    python manage.py schemamigration myapp --initial
    
  5. migrate:

    python manage.py migrate
    

If you want to convert a project:

  1. Run syncdb after adding south
  2. run:

    manage.py convert_to_south myapp

And use south from now on to manage your migrations.

*p.s. - you can add both south and your own app at the same time, if you keep in mind to put south before your own apps. That's because django reads INSTALLED_APPS in order - it runs syncdb on all apps, but after installing south it won't install the rest and instead tell you to use the south commands to handle those

edit

I misled you. Since you put so much emphasis on the south thing I didn't realize the problem was you were trying to use models as a directory module instead of a normal file. This is a recognized problem in django, and the workaround is actually exactly as you though in the first place:

say this is your structure:

project/
       myapp/
            models/
                  __init__.py
                  bar.py

you need bar.py to look like this:

from django.db import models

class Foo(models.Model):
    # fields...

    class Meta:
        app_label = 'myapp' #you need this!

and __init__.py needs to look like this:

from bar import Foo

Make sure it looks like this and it will work.

UPDATE 18/08/2014

The ticket has changed to wontfix, because apparently the bigger issue with the app_label has been fixed. Huzza!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!