【发布时间】:2016-01-31 16:47:12
【问题描述】:
所以我知道已经有很多人提出了很多问题,他们更改了模型,然后未能将迁移应用到他们的数据库。但是,就我而言,我知道迁移已应用,因为我可以看到新的表数据。
基本上,我安装了 django-cms,然后我在 djangocms_column 插件的models.py 中添加了一个字段,以允许我在我的列中添加一个 Bootstrap 类名称(例如col-md-4、col-md-6 等)。
if hasattr(settings, "COLUMN_CLASS_CHOICES"):
CLASS_CHOICES = settings.COLUMN_CLASS_CHOICES
else:
CLASS_CHOICES = (
('col-md-1', _("col-md-1")),
('col-md-2', _("col-md-2")),
('col-md-3', _('col-md-3')),
('col-md-4', _("col-md-4")),
('col-md-5', _('col-md-5')),
('col-md-6', _("col-md-6")),
('col-md-7', _('col-md-7')),
('col-md-8', _('col-md-8')),
('col-md-9', _('col-md-9')),
('col-md-10', _('col-md-10')),
('col-md-11', _('col-md-11')),
('col-md-12', _('col-md-12')),
('', _('none')),
)
...
@python_2_unicode_compatible
class Column(CMSPlugin):
"""
A Column for the MultiColumns Plugin
"""
width = models.CharField(_("width"), choices=WIDTH_CHOICES, default=WIDTH_CHOICES[0][0], max_length=50)
"""
This is the new field:
"""
bs_class = models.CharField(_("bs_class"), choices=CLASS_CHOICES, default=CLASS_CHOICES[0][0], max_length=50)
def __str__(self):
return u"%s" % self.get_width_display()
然后我运行./manage.py makemigrations,然后运行./manage.py migrate,现在表格如下所示:
sqlite> select * from djangocms_column_column;
cmsplugin_ptr_id bs_class width
---------------- ---------- ----------
3 col-md-1 33%
5 col-md-1 33%
7 col-md-1 33%
19 col-md-1 33%
21 col-md-1 33%
23 col-md-1 33%
然而,当我尝试访问测试服务器时,我仍然收到以下错误:
OperationalError at /en/
no such column: djangocms_column_column.bs_class
Request Method: GET
Request URL: http://localhost:8000/en/
Django Version: 1.7.10
Exception Type: OperationalError
Exception Value:
no such column: djangocms_column_column.bs_class
是的,我已经尝试删除数据库并运行./manage.py migrate,但该站点仍然显示相同的错误。是否必须使用特殊的迁移程序来修改安装在./env/lib/python2.7/site-packages 文件夹中的插件?
【问题讨论】:
标签: python django sqlite django-cms django-migrations