4

I have a Django project on a Centos VPS.

I created some models and debugged them so they validate and give no errors. I have them in a "models" folder in my myapp and have added each model to the init file in this directory, for example:

from category import Category

I added the app to settings.py INSTALLED_APPS and ran:

Python manage.py syncdb

It appeared to work fine and added all tables apart from the ones for my app.

I then installed South and added that to INSTALLED_APPS and, tried syncdb again and ran:

Python manage.py schemamigration myapp --initial

It generated the file correctly but nothing was in it (none of the tables my models).

An example file in "models" folder (usertype.py)

from django.db import models

class UserType(models.Model):
    usertype_id = models.PositiveIntegerField(primary_key=True)
    description = models.CharField(max_length=100)
    is_admin = models.BooleanField()
    is_moderator = models.BooleanField()

class Meta:
    app_label = 'myapp'

Any ideas what could be going wrong here and why I can't get anything to detect my models?

4
  • Please edit your original post and add your comment as part of it, it's unreadable like this Commented Jan 23, 2014 at 15:29
  • I've added it to the original post now, any more info needed? Commented Jan 23, 2014 at 16:25
  • See my other comment please Commented Jan 23, 2014 at 16:27
  • Please see my edit for updated solution. Commented Jan 25, 2014 at 11:16

2 Answers 2

10

Run the following commands

python manage.py makemigrations yourappname

python manage.py migrate

Note it works on django 1.7 version for me.

Sign up to request clarification or add additional context in comments.

Comments

8

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!

20 Comments

I am using --initial because it's a new app with no models in db. I tried "manage.py convert_to_south myapp" just to see what happened and it said "This application has no models; this command is for applications that already have models syncdb'd. Make some models, and then use ./manage.py schemamigration myapp --initial instead." As mentioned, I can run --initial and it executes as expected aside from the fact the generated file has nothing in it, it does not detect any of the models. These are new models none of which are in db.
1. The way you described it in your post is not the way I described it 2. Can you share models.py? Also any additional information you think is relevant. I don't think I see the entire problem yet
I have now removed the references from __init__.py in "models" folder as per your recommendation. Thanks for that, though it didn't change my issue as stated with no models being detected.
I didn't expect it to change anything, I just mentioned it.
Cool, I have now added an example of one of the models to the description of the issue above.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.