samedi 29 novembre 2014

PostgreSQL - erreur d'intégrité modèle django - Stack Overflow


so before number field was uncommented i use to get this error Programmingerror: exampeuser.number has no relation to blahblah


class ExampleUser(models.Model):
#number = models.CharField(max_length=15)
phoneID = models.CharField(max_length=30)
verified = models.BooleanField(default=False)
verificationNumber = models.CharField(max_length=5)

now i comment it and syncdb and everything, it gives me an IntegrityError: null value in column "userPhone" violates not-null constraint when i try to save it in the admin website.


userPhone was a field i used a while back and changed it to number.


those errors occur everytime i try to save a model object in the admin site.


it seems that my model is still ineteracting with old changes i made previously. I am new to django.


i also have south on my installed_app and i have not yet migrated or made any configs with it. please help , this is very fustrating




It seems like you're trying to migrate your model, for example, you write a model, then you sync it, then you modify it, change some data types, delete some attributes and add some other and then sync it again.


Django does not support this by default, you need to use South(1) a library that migrates your models through this changes.


Unless you're using django 1.6, in this version they added migrations, here is the documentation. https://docs.djangoproject.com/en/dev/topics/migrations/


Whenever you need to sync a modified model, you need to do it with a migration, not with syncdb.


(1) http://south.aeracode.org/



so before number field was uncommented i use to get this error Programmingerror: exampeuser.number has no relation to blahblah


class ExampleUser(models.Model):
#number = models.CharField(max_length=15)
phoneID = models.CharField(max_length=30)
verified = models.BooleanField(default=False)
verificationNumber = models.CharField(max_length=5)

now i comment it and syncdb and everything, it gives me an IntegrityError: null value in column "userPhone" violates not-null constraint when i try to save it in the admin website.


userPhone was a field i used a while back and changed it to number.


those errors occur everytime i try to save a model object in the admin site.


it seems that my model is still ineteracting with old changes i made previously. I am new to django.


i also have south on my installed_app and i have not yet migrated or made any configs with it. please help , this is very fustrating



It seems like you're trying to migrate your model, for example, you write a model, then you sync it, then you modify it, change some data types, delete some attributes and add some other and then sync it again.


Django does not support this by default, you need to use South(1) a library that migrates your models through this changes.


Unless you're using django 1.6, in this version they added migrations, here is the documentation. https://docs.djangoproject.com/en/dev/topics/migrations/


Whenever you need to sync a modified model, you need to do it with a migration, not with syncdb.


(1) http://south.aeracode.org/


0 commentaires:

Enregistrer un commentaire