manage.py migrate未在生产中激活...列X不存在......为什么?

时间:2016-04-10 02:33:54

标签: python django database postgresql amazon-web-services

我收到了这个错误;

ProgrammingError at /
column main_category.parent_cat_id does not exist
LINE 1: ...n_category"."author_id", "main_category"."image", "main_cate. and I believe this means parent_cat_id isn't in the database. 

这是我不明白的,我将其设置为null=trueblank=true ....这在本地开发服务器中有效。错误只发生在生产中。(我正在使用弹性豆秆)

class Category(models.Model): 
    name = models.CharField(max_length=128, unique=True)
    author = models.ForeignKey(settings.AUTH_USER_MODEL)

    parent_cat = models.ForeignKey('self', null=True, blank=True)
    hotCat = models.BooleanField(default=False)
    active = models.BooleanField(default=True)

    sponsored = models.ForeignKey(Sponsored, null=True, blank=True)


    objects = CategoryManager()

    def __unicode__(self): 
        return self.name

    def get_absolute_url(self):
        return "/category/%s/" %self.name

    def get_image_url(self):
        return "%s%s" %(settings.MEDIA_URL, self.image)

编辑:

这是我的python配置文件,你可以看到我已经迁移了

container_commands:
  01_migrate:
    command: "source /opt/python/run/venv/bin/activate && python myproject/manage.py migrate --noinput"
    leader_only: true

  02_uninstall_pil:
    command: "source /opt/python/run/venv/bin/activate && yes | pip uninstall Pillow"

  03_reinstall_pil:
    command: "source /opt/python/run/venv/bin/activate && yes | pip install Pillow --no-cache-dir"

  04_createsu:
    command: "source /opt/python/run/venv/bin/activate && python myproject/manage.py createsu"
    leader_only: true

  05_collectstatic:
    command: "source /opt/python/run/venv/bin/activate && python myproject/manage.py collectstatic --noinput"

  06_checkpermission:
    command: "source /opt/python/run/venv/bin/activate && python myproject/manage.py check_permissions"


option_settings:
  "aws:elasticbeanstalk:application:environment":
    DJANGO_SETTINGS_MODULE: "myproject.settings"
    "PYTHONPATH": "/opt/python/current/app/myproject:$PYTHONPATH"
  "aws:elasticbeanstalk:container:python":
    WSGIPath: myproject/myproject/wsgi.py

我的追溯

Traceback:
File "/opt/python/run/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/python/current/app/myproject/main/views.py" in index
  64.       request.session['categories'] = [ c.name for c in Category.objects.filter(author=request.user.id)] # add to the session 
File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/models/query.py" in __iter__
  162.         self._fetch_all()
File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
  965.             self._result_cache = list(self.iterator())
File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  238.         results = compiler.execute_sql()
File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  840.             cursor.execute(sql, params)
File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/utils.py" in __exit__
  97.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /
Exception Value: column main_category.parent_cat_id does not exist
LINE 1: ...n_category"."author_id", "main_category"."image", "main_cate...
                                                             ^

我的迁移文件

operations = [
    migrations.CreateModel(
        name='Category',
        fields=[
            ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
            ('name', models.CharField(unique=True, max_length=128)),
            ('description', models.TextField(verbose_name=b'\xec\xbb\xa4\xeb\xae\xa4\xeb\x8b\x88\xed\x8b\xb0 \xec\x84\xa4\xeb\xaa\x85')),
            ('image', models.ImageField(upload_to=b'images/', null=True, verbose_name=b'\xec\xbb\xa4\xeb\xae\xa4\xeb\x8b\x88\xed\x8b\xb0 \xeb\x8c\x80\xed\x91\x9c \xec\x9d\xb4\xeb\xaf\xb8\xec\xa7\x80', blank=True)),
            ('hotCat', models.BooleanField(default=False)),
            ('active', models.BooleanField(default=True)),
            ('author', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
            ('parent_cat', models.ForeignKey(blank=True, to='main.Category', null=True)),
        ],
    ),

0 个答案:

没有答案