Reputation: 311
I am usign Django South for the first time.I have already succeed to update my database using Django South without deleting my whole database. This was the query django south migration error relation “photo_photo” already exists
but i am facing a error whenever i want to add a new model.In mention i have added all the staff in my admin.py file
The above given query was about the change in a existing model and thankfully i have successfully updated my database.
But after following the same command from South Tutorial ,i can not able to add a new model in my database,apparently the model is showing in the django admin site,but after i click on to that model or after i want save anything on to that model,i am facing the following error
DatabaseError at /admin/photo/userreferralcode/
relation "photo_userreferralcode" does not exist
LINE 1: SELECT COUNT(*) FROM "photo_userreferralcode"
My model.py
class UserReferralCode(models.Model):
owner = models.CharField(max_length=300,blank=True,null=True)
referral_code = models.CharField(max_length=300,blank=True,null=True)
created_time = models.DateTimeField(auto_now_add=True)
updated_time = models.DateTimeField(auto_now=True)
my admin.py
from app.models import UserReferralCode
admin.site.register(UserReferralCode)
and i have also added admin.autodiscover()
in my main urls.py
.
in mention for a new migration(since i have intended to add a new model)i have wrote the following command step by step
first
python manage.py schemamigration photo --initial
then second
python manage.py migrate photo
then third
python manage.py schemamigration photo --auto
then fourth
python manage.py migrate photo
then
python manage.py syncdb
after doing all these staff the model UserReferralCode
has been added in the django admin site ,i can see it,but clicking on this newly added model or after saving anything on this model,i am facing the above given error,i am giving it here again.
DatabaseError at /admin/photo/userreferralcode/
relation "photo_userreferralcode" does not exist
LINE 1: SELECT COUNT(*) FROM "photo_userreferralcode"
in mention my app name is photo
now whats the problem or what i am missing here.
Upvotes: 0
Views: 417
Reputation: 1518
--initial
is used when first migration for application created. After that --auto
is used every time you change models or add new one. (For another django application you run --initial
with its first migration, and so on)
So, considering your previous question, you should apply the following steps:
Photo
and UserCommission
to your models.py
.python manage.py schemamigration photo --initial
.python manage.py migrate photo
.UserReferralCode
to models.py
.python manage.py schemamigration photo --auto
.python manage.py migrate photo
.By the way, once you get used migrate
, you don't have to use syncdb
, since migrate
intended to replace syncdb
in a more convenient way.
Upvotes: 2