Question

Specifically I'm looking for a schemamigration using Django, here is some of my code:

From

class Login(models.Model):
    username = models.CharField(max_length=30)
    password = models.CharField(max_length=30)
    email = models.EmailField()
    member_date = models.DateTimeField()

    def __unicode__(self):
        return self.username

To

class Login(models.Model):
    username = models.CharField(max_length=30)
    password = models.CharField(max_length=30)
    email = models.EmailField()
    member_date = models.DateTimeField(auto_now_add=True, blank=True) # changes here

    def __unicode__(self):
        return self.username
Était-ce utile?

La solution

What you're looking for is a way to do a data migration (specifically, a schemamigration). Please see the South Documentation for an easy tool to do this.

It essentially replaces syncdb for whatever apps you tell it to, and then can have it automatically write the migration. While this might seem like more work than it's worth at the beginning, once you get to the point where you have real data in your database, you'll find it's great to not have to delete (and then recreate) the tables each time you update your models.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top