Django 异常值:home\u profile.goal列不存在

Django 异常值:home\u profile.goal列不存在,django,postgresql,sqlite,heroku,django-1.10,Django,Postgresql,Sqlite,Heroku,Django 1.10,我真的被困在这里,我有点困惑,为什么会抛出这个错误。我运行的是Django 1.10,实时数据库是postgresql数据库。我对博士后不太熟悉。为了灵活性,我一直在使用sqlite进行所有的开发工作 我最近在模型中添加了两个新字段。它们都是IntegerFields我在本地没有遇到任何问题。我还没有将我的更改部署到我的实时环境中,我得到了上面的错误 goal = models.IntegerField(default=1, choices=weight_goal, null=True, bla

我真的被困在这里,我有点困惑,为什么会抛出这个错误。我运行的是Django 1.10,实时数据库是postgresql数据库。我对博士后不太熟悉。为了灵活性,我一直在使用sqlite进行所有的开发工作

我最近在模型中添加了两个新字段。它们都是
IntegerFields
我在本地没有遇到任何问题。我还没有将我的更改部署到我的实时环境中,我得到了上面的错误

goal = models.IntegerField(default=1, choices=weight_goal, null=True, blank=True)
我尝试过删除字段,删除所有迁移文件,甚至删除模型本身。但是,当我将字段添加回时,它会抛出相同的错误

我已经做了一些研究,我所能看到的就是“删除数据库,然后再创建一次”。这是不可能的,因为我会丢失实时数据库中的所有数据

我真的不喜欢潜入一个实时数据库并尝试手动添加列。我的意思是,这似乎有点奇怪

注意:我正在通过Heroku部署box

配置文件模型:

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)

    image = CloudinaryField('image', default="thumbnail_mqe6ne")
    weight = models.DecimalField(help_text="KG", max_digits=5, default=0, decimal_places=2, validators=[
        MinValueValidator(30),
        MaxValueValidator(600)
        ])
    height = models.DecimalField(help_text="CM", max_digits=8, default=0, decimal_places=2, validators=[
        MinValueValidator(20),
        MaxValueValidator(600),
        ])

    gender_option = (
        ('Male', 'Male'),
        ('Female', 'Female'),
    )

    profile_status = (
        ('Public', 'Public'),
        ('Private', 'Private'),
    )



    birth_date = models.DateField(blank=True, verbose_name="Date of Birth")


    gender = models.CharField(choices=gender_option, max_length=10)
    bio = models.TextField(max_length=300, blank=True)
    location = models.CharField(max_length=30, blank=True)


    weight_goal = (
        (1, 'Weight Loss'),
        (2, 'Weight / Muscle weight gain'),
    )

    goal = models.IntegerField(default=1, choices=weight_goal, null=True, blank=True)

    activity = (
        (1, 'Mostly inactive or sedentary'),
        (2, 'Fairly active'),
        (3, 'Moderately active'),
        (4, 'Active'),
        (5, 'Very active'),
    )


    activity_level = models.IntegerField(default=1, choices=activity, null=True, blank=True)


    intensity = (
        (1, 'Very light training'),
        (2, 'Moderate intensity'),
        (3, 'Moderate to high intensity (1 - 3 hours)'),
        (4, 'Very high intensity training (4+ Hours Daily)'),

    )


    training_intensity = models.IntegerField(default=1, choices=intensity)


    status = models.CharField(default="Public", max_length=10, choices=profile_status)
任何帮助都将非常感谢。完整回溯如下:

Environment:


Request Method: GET
Request URL: /

Django Version: 1.10
Python Version: 2.7.13
Installed Applications:
['djangocms_admin_style',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.sites',
 'stats',
 'home',
 'blog',
 'haystack',
 'ckeditor_uploader',
 'ckeditor',
 'django_social_share',
 'post_office',
 'sorl.thumbnail',
 'storages',
 'cloudinary',
 'django.contrib.staticfiles',
 'cloudinary_storage',
 'django_cleanup',
 'django_instagram',
 'embed_video',
 'easy_thumbnails',
 'filer',
 'reversion',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.facebook']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'solid_i18n.middleware.SolidLocaleMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.middleware.locale.LocaleMiddleware']



Traceback:

File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  39.             response = get_response(request)

File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/app/home/views.py" in get_user_profile
  42.     profile = Profile.objects.get(user=request.user.id)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
  85.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py" in get
  379.         num = len(clone)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py" in __len__
  238.         self._fetch_all()

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
  1085.             self._result_cache = list(self.iterator())

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py" in __iter__
  54.         results = compiler.execute_sql()

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  835.             cursor.execute(sql, params)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py" in __exit__
  94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /profile/
Exception Value: column home_profile.goal does not exist
LINE 1: ... "home_profile"."bio", "home_profile"."location", "home_prof...
                                                         ^

如果您还没有这样做,那么要做的第一件事就是创建数据库的备份

数据库是一个postgresql数据库。我对postgres不太熟悉。为了灵活性,我一直在使用sqlite进行所有的开发工作

对于非平凡的项目,最好在两端使用相同的RDBMS

我做了一些研究,我所能看到的只是‘放下数据库,重新创建它’

你不走这条路是对的。那是很糟糕的建议

我尝试过删除字段,删除所有迁移文件,甚至删除模型本身。但是,当我将字段添加回时,它会抛出相同的错误

但这也是一条非常孤独和危险的道路,你走的路充满了陷阱。让我们看看能不能把事情纠正过来

postgresql抱怨该列丢失的事实清楚地表明您有一个恶意的迁移。检查备份,看看是否有一个版本的db,包含该列。如果不这样做,您将丢失一些数据

如果您有这样的备份,请在通过psql或pgadmin目视检查数据库中是否确实缺少该列后将其还原

现在您已经清除了迁移,请完全清空该文件夹。确保周围没有任何
.pyc
文件

接下来检查您的
django_迁移
表。删除与当前应用程序相关的迁移(
home
我想)

下一步

./manage.py makemigrations home
这将在您的migrations文件夹中创建一个迁移。确认后做什么

./manage.py migrate --fake-initial home

现在一切都应该正常了。

如果在本地添加了任何字段,请确保在live数据库上运行迁移嘿!是的,我试过在heroku box上运行迁移,你能发布你的主页吗?或者检查模型中是否存在目标字段,以及live server中是否存在目标字段,我已经添加了概要文件模型。我已经检查了live站点,模型文件完全相同。goal=models.IntegerField(默认值=1,choices=weight\u goal,null=True,blank=True)将此设置为CharField,然后上载到服务器并首先运行makemigrations,然后进行迁移并让我知道\n感谢您的详细响应:)我一直在播放并备份数据库等。我已经删除了迁移文件,当我运行“makemigrations”命令时,它会正常运行并创建初始文件。但是,当我运行“migrate--false initial home”时,它只会抛出以下内容:要执行的操作:应用所有迁移:home Running迁移:没有要应用的迁移。可能是因为您没有删除
django_migrations
表中的相关条目。现在这并不重要,但下次你需要迁移时它会回来咬你。好的,我已经删除了django_迁移中家庭应用的条目。然后像上面那样运行命令,我得到了同样的错误。你确定你已经精确地完成了所有步骤吗?我想还有一些额外的信息没有被披露。否则,thsi配方可以工作(正如您所说,您已经发现它可以在sqlite上工作)。无论如何,如果您有一个正常的安装,只需使用fake标记迁移已经应用,一切都会很好。