Friday, May 17, 2013

South not picking up changes to model, app crashes

So I created a service record model like this:

class ServiceRecord(models.Model):

    location = models.ForeignKey(Location, related_name='service_records')
    created = models.DateTimeField(auto_now_add=True, null=True)
    modified = models.DateTimeField(auto_now=True, null=True)
    active = models.NullBooleanField(default=True, blank=True, null=True)
    service_provider = models.CharField(max_length=50, blank=True, null=True)
    service_date = models.DateField(blank=False, null=True)
    emergency = models.BooleanField(default=False, blank=True)
    emergency_date = models.DateField(blank=True, null=True)
    description = models.TextField(blank=True, null=True)
    parts_used = models.TextField(blank=True, null=True)
    warranty = models.BooleanField(default=False, blank=True)
    verified = models.BooleanField(default=False, blank=True)


I then converted my app to south

Install South on server

Import south from shell just to make sure you are using the same python env.

python manage.py syncdb.

python manage.py convert_to_south myproject.locations

This went fine:
 + Added model locations.Location   + Added model locations.Photo   + Added model locations.WaterSource   + Added model locations.WaterStorage   + Added model locations.PumpSystem   + Added model locations.PressureTank   + Added model locations.CartridgeFilter   + Added model locations.DisinfectionUnit   + Added model locations.TreatmentEquipment   + Added model locations.WasteSystem   + Added model locations.WaterSample   + Added model locations.Schematic   + Added model locations.Contact   + Added M2M table for locations on locations.Contact   + Added model locations.ServiceRecord  Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate locations   - Soft matched migration 0001 to 0001_initial.  Running migrations for locations:  - Nothing to migrate.   - Loading initial data for locations.  Installed 0 object(s) from 0 fixture(s)    App 'locations' converted. Note that South assumed the application's models matched the database  (i.e. you haven't changed it since last syncdb); if you have, you should delete the locations/migrations  directory, revert models.py so it matches the database, and try again.  



I then added a user key to it so I can track who created the record,     user = models.ForeignKey(User) added:

class ServiceRecord(models.Model):

    location = models.ForeignKey(Location, related_name='service_records')
    user = models.ForeignKey(User)
    created = models.DateTimeField(auto_now_add=True, null=True)
    modified = models.DateTimeField(auto_now=True, null=True)
    active = models.NullBooleanField(default=True, blank=True, null=True)
    service_provider = models.CharField(max_length=50, blank=True, null=True)
    service_date = models.DateField(blank=False, null=True)
    emergency = models.BooleanField(default=False, blank=True)
    emergency_date = models.DateField(blank=True, null=True)
    description = models.TextField(blank=True, null=True)
    parts_used = models.TextField(blank=True, null=True)
    warranty = models.BooleanField(default=False, blank=True)
    verified = models.BooleanField(default=False, blank=True)

Then i did, 
python manage.py migrate locations –fake 000

 - Soft matched migration 0001 to 0001_initial.
Running migrations for locations:
- Nothing to migrate.
 - Loading initial data for locations.
Installed 0 object(s) from 0 fixture(s)


and then  where I thought it would find the user_id field..
python manage.py migrate apppython manage.py syncdb

Running migrations for locations:
- Nothing to migrate.
 - Loading initial data for locations.
Installed 0 object(s) from 0 fixture(s)


It did not migrate it and when I checked the database I saw it was not there and the app was just crashing complaining about the user_Id field. What am I doing wrong here? Any help would be appreciated. I ended up deleting the table and doing syncdb instead and had to manually get all the data back in.. Would really love to avoid this.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate