django向南迁移错误关系“ photo_photo”;已经存在 [英] django south migration error relation "photo_photo" already exists

查看:78
本文介绍了django向南迁移错误关系“ photo_photo”;已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django South。我正在遵循 http:// south.readthedocs.org/en/latest/tutorial/part1.html

I am using Django South.I am following the tutorial of http://south.readthedocs.org/en/latest/tutorial/part1.html

首先,我想提供一些有关我的项目和应用程序的信息。
我有一个django应用,即 photo ,我有两个模型,分别是 Photo UserCommission

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.

这些是模型

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)

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

  python manage.py migrate photo

,最后我的第一次迁移成功完成,并且编辑的列已添加到照片模型中!

and finally my first migration has successfully done and the edited columns are added in the Photo model!

现在在另一种情况下,我必须更改我的 UserCommission 模型,为此我也遵循相同的方法我的第一次迁移遵循的过程。但是在第二次迁移的最后一个命令之后,是

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

我遇到以下错误

正在运行照片的迁移:
-转发到0002_initial。

Running migrations for photo: - Migrating forwards to 0002_initial.


photo:0001_initial
致命错误-以下SQL查询失败:CREATE TABLE photo_photo( id串行NOT NULL主键, name varchar(100)NOT NULL, photo varchar(100)NULL, approved布尔型NOT NULL, approved_time时间戳记区域NULL,带有时区的 uploaded_time时间戳NOT NULL,描述 varchar(500)NULL,关键字 varchar(500)NULL, image_id varchar(300)NULL, Certified布尔值NOT NULL, approved_by varchar(100)NOT NULL, user_id完整er NOT NULL, total_download整数NOT NULL, watermarked_image varchar(100)NULL, dpi_value整数NOT NULL)
错误是:关系 photo_photo已经存在
迁移错误:photo :0001_initial
DatabaseError:关系 photo_photo已存在

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.

推荐答案

听起来像已经应用了迁移,而数据库认为还没有。您始终可以 migrate --fake 仅更新数据库中的表,而无需尝试应用迁移。

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.

在您的情况下,您似乎(至少)需要 python manage.py迁移照片--fake 0002 。对于多个迁移,您可能需要执行此操作,具体取决于您已有多少迁移和完成的迁移。

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.

这篇关于django向南迁移错误关系“ photo_photo”;已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆