0

I have looked at these questions; http://south.readthedocs.org/en/latest/tutorial/part1.html, South ignores change in field default value in Python / Django & Django-south not detecting DB changes and many more all over SO but I can't seem to fix my problem.

I have an existing model with data in it's tables, and I'm adding another model via Foreign key to it. I have run schema migrations and migrations, but nothing has proved to work. This is the code:

class UserNote(models.Model):
   user = models.ForeignKey(User)
   description = models.TextField(blank=True, null=True)

   created_at = models.DateTimeField(auto_now_add=True)
   updated_at = models.DateTimeField(auto_now=True)



class UserNoteType(models.Model):
    name = models.CharField(max_length=20)

I need to add UserNoteType to UserNote as Foreign key,and every attempt to add the field results in "not installed", "not defined". I've been battling with this for hours now, any help would assist greatly.

EDIT: Error I recieve when I try create a Schema-migration:

CommandError: One or more models did not validate: auth.usernote: 'note_type' has a relation with model , which has either not been installed or is abstract.

Community
  • 1
  • 1
tseboho
  • 77
  • 10
  • Can you post the full error message? Does it say anything more than just "not installed" or "not defined"? Basically, what is the full south command that you are running, and the full output of the error. – Pierre Drescher Jul 25 '14 at 14:33
  • It just mentions the model. – tseboho Jul 25 '14 at 14:34
  • CommandError: One or more models did not validate: auth.usernote: 'note_type' has a relation with model , which has either not been installed or is abstract. – tseboho Jul 25 '14 at 14:35
  • It might not be an error with south, but with your models in general. What happens if you just run python manage.py runserver, do you also get the same error? The first thing to do is make sure your models validate. Can you post the full model file? Including the UserNote model? – Pierre Drescher Jul 25 '14 at 14:38
  • I am not using .manage, I'm using django-admin.. My server runs perfectly. I only get this problem with these migration attempts. – tseboho Jul 25 '14 at 14:45
  • You need to place UserNoteType class before UserNote to use it as a ForeignKey. – rphonika Jul 25 '14 at 14:48
  • I have also attempted that. I even went as far as pulling it into its own file and importing it. – tseboho Jul 25 '14 at 14:49
  • Your Model already exists within your DB. Delete the *migrations* folder and execute `./manage convert_to_south my_app`. – rphonika Jul 25 '14 at 14:54

3 Answers3

0

Have you tried to convert your existing app for South with the following command ?

python manage.py convert_to_south my_app

More informations can be find here

rphonika
  • 1,071
  • 10
  • 11
  • thank you for your response. When I attempt that I get back the error, "There is no enabled application matching 'models'". Even after running django-admin.py syncdb as is suggested. – tseboho Jul 25 '14 at 13:58
  • If you have migrate your model just one time, delete the ´migrations´ folder within your app and execute the ´convert_to_south command´. Otherwise can you list the commands you run in the correct order. In this way, it should be easier to understand your error. – rphonika Jul 25 '14 at 14:36
  • I removed the foreign key field > ran schemamigration --initial on the application > then added the foreign key to the UserNote model > ran another schemamigration, this time with --auto. And I still receive the error, "note_type' has a relation with model , which has either not been installed or is abstract." – tseboho Jul 25 '14 at 14:40
0

For your reference

If you are creating new project, beginning it's self you need to setup south, Try below:

python manage.py syncdb

python manage.py schemamigration --initial firstapp

python manage.py migrate forecasts --fake


python manage.py schemamigration --auto firstapp

python manage.py migrate google

After the development side you are planning to include south, then try below

./manage.py schemamigration --auto firstapp

./manage.py migrate firstapp
Raja Simon
  • 10,126
  • 5
  • 43
  • 74
  • The project is already in development, and the sequence you wrote is the same as the one I followed. I'm starting to believe that the error lies outside of south, and I am looking into exactly that. – tseboho Jul 25 '14 at 14:44
  • Not sure but i suggest this one take look https://docs.djangoproject.com/en/1.6/ref/models/fields/#django.db.models.ForeignKey.related_name – Raja Simon Jul 25 '14 at 14:48
0

The UserNote model was attached to the Django UserAuth application. This resulted with South looking in the wrong application each time. I fixed this issue by creating a custom command to manually insert the new column note_type to the UserNote table.

Thank you so much for your help.

tseboho
  • 77
  • 10