问题
I am using Django South.I am following the tutorial of http://south.readthedocs.org/en/latest/tutorial/part1.html
first of all i want to give some information about my project and the apps.
I have a django app namely photo
and i have two model namely Photo
and UserCommission
.
these are the models
class Photo(models.Model):
name = models.CharField(max_length = 100)
photo = models.ImageField(upload_to = 'photos', blank=False,null=True)
approved = models.BooleanField(default = False)
approved_time = models.DateTimeField(auto_now=True,null=True,blank=True)
uploaded_time = models.DateTimeField()
description = models.CharField(max_length = 500 , blank = False , null = True)
and
class UserCommission(models.Model):
user = models.ForeignKey(User)
created_time = models.DateTimeField('Created Time',auto_now_add=True)
commission = models.IntegerField()
photo_name=models.CharField(max_length=255)
photo = models.ImageField(upload_to='commission_image')
download = models.DateTimeField()
photo_id = models.CharField(max_length=300)
for my first migration i have applied the following according to the tutorial,
python manage.py schemamigration photo --initial
and immediately i have apply the following command
python manage.py migrate photo
then i made a change in my Photo
model and apply the following command for final migration
python manage.py schemamigration photo --auto
and
python manage.py migrate photo
and finally my first migration has successfully done and the edited columns are added in the Photo
model!
now in another situation,i have to make change in my UserCommission
model and for that i have followed the same process i have followed for my first migration.but after the last command for this second migration that is
python manage.py migrate photo
i am facing the following error
Running migrations for photo: - Migrating forwards to 0002_initial.
photo:0001_initial FATAL ERROR - The following SQL query failed: CREATE TABLE "photo_photo" ("id" serial NOT NULL PRIMARY KEY, "name" varchar(100) NOT NULL, "photo" varchar(100) NULL, "approved" boolean NOT NULL, "approved_time" timestamp with time zone NULL, "uploaded_time" timestamp with time zone NOT NULL, "description" varchar(500) NULL, "keyword" varchar(500) NULL, "image_id" varchar(300) NULL, "Certified" boolean NOT NULL, "approved_by" varchar(100) NOT NULL, "user_id" integer NOT NULL, "total_download" integer NOT NULL, "watermarked_image" varchar(100) NULL, "dpi_value" integer NOT NULL) The error was: relation "photo_photo" already exists Error in migration: photo:0001_initial DatabaseError: relation "photo_photo" already exists
DatabaseError: relation "photo_photo" already exists
and tell you what, its really bothering me.
回答1:
Sounds like that migration has already been applied and the database thinks it hasn't. You can always migrate --fake
to just update the table in the database without trying to apply the migration.
In your case, it looks like you need to (at least) python manage.py migrate photo --fake 0002
. You may have to do this for more than one migration depending on how many you have and what you've done.
来源:https://stackoverflow.com/questions/28735525/django-south-migration-error-relation-photo-photo-already-exists