0

I'm having trouble trying to add south to an existing django project. Here is my situation:

My project is called alerts. Here is my folder structure:

djangoprojects/
    alerts/
        manage.py
        alerts/
            __init__.py
            urls.py
            views.py
            models.py
            wsgi.py
            settings.py
        common/
            __init__.py
            models/
                __init__.py
                models.py

The file alerts/alerts/models.py has the following content:

from common.models.models import *

In other words, the only thing that alerts/alerts/models.py does is import the "real" models from alerts/common/models/models.py, which has a large number of models that were created from a past project.

I also have a MYSQL database that I'll call 'existing_database'. This is the database that corresponded to the models on my past project, which ran on another machine. On that other machine I used mysqldump to get the sql file for this database and copied it over to my new machine. Then I used mysql directly to create existing_database on my new machine. So now the database existing_database should match the models in alerts/common/models/models.py.

So next I went through the documentation to try to add south to the alerts project. This is what I did:

  1. I added 'south' and 'alerts' to the INSTALLED_APPS inside alerts/alerts/settings.py. I'm not sure why I have to add 'alerts' to settings.py inside the alerts project - you'd think the fact that the settings file was in the project folder would be enough. But it complained if I didn't add it explicitly, so I did.
  2. I cd-ed to djangoprojects/alerts and ran ./manage.py syncdb. It said it synced some stuff, including south and alerts
  3. Then I ran ./manage.py convert_to_south alerts. This is where I ran into problems. 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 alerts --initial instead.
  4. So I tried running ./manage.py schemamigration alerts --initial. It created an initial migration but that migration files has almost nothing in it. All it has is a class Migration. None of my real models are anywhere to be found.
  5. To see if it can recognize any new models, I went to common/models/models.py and added a dummy model. Then I ran ./manage.py schemamigration alerts --auto and the response I got back was "Nothing seems to have changed". So it apperas it still knows nothing about my real models.

Ao at this point I'm totally confused. Like I said, I have an existing database with real data, and I have an existing set of models code that should exactly represent that actual table structure. I just want to start using this in my alerts project and I need south because I will be adding and changing models.

How do I accomplish this?

Marc
  • 3,386
  • 8
  • 44
  • 68
  • Try setting 'app_label' at your models' Meta class. – cngkaygusuz Mar 29 '14 at 00:17
  • I have a ton of existing models. I didn't need to do this on my prior project. Are you saying I have to do this on each and every model? – Marc Mar 29 '14 at 00:21
  • I guess the problem is that your app has the same name as the project, maybe try to rename either? – sk1p Mar 29 '14 at 00:37
  • Naming has nothing to do with the problem. When you run "python manage.py startapp appname" to create a project. It will create the appname project and create appname as the name of the app in the project. If this were a problem then the startapp command wouldn't do this. – Marc Mar 29 '14 at 00:59
  • @marc, you would have had to do it in your previous projects. Django cannot recognize models defined outside app/models.py as you'll find in many posts about separating models.py into several other files. http://stackoverflow.com/questions/5534206/how-do-i-separate-my-models-out-in-django Finally you have another problem which is that your models.py isn't actually even in an app, it's in a folder called `common` inside another app. This is another further departure from `app/models.py -> app/models/__init__.py+` so I'm not surprised it doesn't work. Try adding `common` to your installed apps. – Yuji 'Tomita' Tomita Mar 29 '14 at 01:11

0 Answers0