无法在迁移中添加新字段:“column .. not exist” [英] Can't add a new field in migration: "column .. does not exist"

查看:154
本文介绍了无法在迁移中添加新字段:“column .. not exist”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给我的模型添加一个字段,但我完全迷失在这里。这是模型,应用程序名称称为个人资料:

 类配置文件(models.Model):
user = models.OneToOneField(User,unique = True,null = True)
nickname = models.CharField(max_length = 75,null = True)#new field
description = models.CharField(max_length = ,blank = True,null = True)

所以,我添加了昵称字段。然后我跑了

  python manage.py schemamigration profiles --auto 
python manage.py migrate profiles

但是它给了我一个错误。 关系profiles_profiles已经存在。



所以我做了

  python manage.py迁移配置文件--fake 
python manage.py迁移配置文件

然后我尝试使用模型我得到错误

  ProgrammingError:列profiles_profiles.nickname不存在

当我尝试迁移时,我收到的消息是:



<$ p $

没有什么可以改变

当我尝试做一个模式迁移和迁移。 :/?¿。



感谢任何帮助。

解决方案

正确的命令将是:

 code> python manage.py schemamigration< app_name> --auto 

您必须输入应用程序的名称不是模型


I want to add a field to my model but I'm completely lost here. This is the model, the app name is called "profiles":

class Profiles(models.Model):
    user = models.OneToOneField(User, unique=True, null=True)
    nickname = models.CharField(max_length=75, null=True)  # new field
    description = models.CharField(max_length=250, blank=True, null=True)

So, I added the "nickname" field. Then I ran

python manage.py schemamigration profiles --auto
python manage.py migrate profiles

But it gave me an error. "relation profiles_profiles already exists."

So I did

python manage.py migrate profiles --fake
python manage.py migrate profiles

and then when I try to work with the model I get the error

ProgrammingError: column profiles_profiles.nickname does not exist

The message I get when I try to migrate is:

"nothing to migrate"
and 
"nothing seems to have changed"

when I try to do a schemamigration and a migration. :/ ?¿.

I would appreciate any help.

解决方案

The correct command would be:

python manage.py schemamigration <app_name> --auto

You've to write the name of the app, not of the model.

这篇关于无法在迁移中添加新字段:“column .. not exist”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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