当前位置 : 主页 > 网络编程 > 其它编程 >

django没有列-Columndoesnotexistindjango1.6.5

来源:互联网 收集:自由互联 发布时间:2023-07-02
IhaveanapplicationinDjango1.6.5.IhaveamodelwhereIremovedonefield,Iaddedanotherfie I have an application in Django 1.6.5. I have a model where I removed one field, I added another field, and the third upgraded. And when we now turn to the mod
IhaveanapplicationinDjango1.6.5.IhaveamodelwhereIremovedonefield,Iaddedanotherfie

I have an application in Django 1.6.5. I have a model where I removed one field, I added another field, and the third upgraded. And when we now turn to the model in the admin panel, I get the message:

我有一个Django 1.6.5的应用程序。我有一个模型,我删除了一个字段,添加了另一个字段,第三个字段升级了。当我们现在转向管理面板中的模型时,我得到了一个信息:

ProgrammingError at /admin/app/subscription/column app_subscription.enabled does not exist

The command python manage.py syncdb does not work.

python命令管理。py syncdb不起作用。

2 个解决方案

#1

2

Django (hopefully) doesn't modify your database schema if you don't explicitely ask for it. The syncdb command works perfectly, but (as documented) it will only create tables that don't yet exists (and are not marked as being managed externally in your models).

如果您不明确地要求的话,Django(希望如此)不会修改您的数据库模式。syncdb命令工作得很好,但是(如文档所示)它只创建尚未存在的表(并且在模型中没有被标记为外部管理)。

So you have mostly three options here:

所以你有三个选择:

  • manually drop your table and re-run syncdb. This mean you will loose all our data, so it's hardly a "solution"
  • 手动删除表并重新运行syncdb。这意味着你会丢失我们所有的数据,所以这不是一个“解决方案”
  • manually alter your database schema. You won't loose your data, but you'll have to repeat the same (manual) operation everywhere your app is deployed... If it's only installed on your local workstation that might be ok, else it's not a reliable professional production-level option.
  • 手动修改数据库模式。你不会丢失你的数据,但是你必须在你的应用部署的任何地方重复同样的(手动)操作……如果它只安装在您的本地工作站上,可能是可以的,否则它不是一个可靠的专业生产级选项。
  • Use South (which seems to be installed since you do have a migrate command available.
  • 使用South(似乎是安装的,因为您确实有一个迁移命令可用。
  • Note that solution #3 imply that you do create the migration files for your app, as documented here : http://south.readthedocs.org/en/latest/tutorial/part1.html#the-first-migration

    请注意解决方案#3暗示您确实为您的应用创建了迁移文件,如本文所述:http://south.readthedocs.org/en/latest/tutorial/part1.html#the first-migration

    #2

    0

    It just happened that I faced the same issue with django 1.9.x, where I added a new field in my django app which triggered the same error as you mentioned above. I logged into the dbshell environment using

    碰巧我在django 1.9中遇到了同样的问题。我在django应用程序中添加了一个新字段,它触发了您上面提到的错误。我使用dbshell环境登录

    python manage.p dbshell # I know some use ./manage.py

    and dropped all of my tables by running the following command within the dbshell to drop the tables

    并通过在dbshell中运行以下命令删除所有表

    your_psql=# drop schema public cascade;

    This will drop all of your tables (be careful as you may lose your data, there away to keep the data!) and you will get a message right after executing this command tells you that all dropped. Right after that run the following command to create the schema again, otherwise your server will not run:

    这将删除所有的表(注意,您可能会丢失数据,将数据保存在那里!)运行以下命令再次创建模式,否则您的服务器将不会运行:

    your_psql=# create schema public;

    Then just do the

    然后就做

    python manage.py makemigrations # you might not need this, and python manage.py migrate

    And you're ready to go.

    你准备好了。

    I know this answer might be very late but I hope it will help someone.

    我知道这个答案可能会很晚,但我希望它能帮助某人。

    Cheers

    干杯

    上一篇:[牛客算法总结]:修剪叶子
    下一篇:没有了
    网友评论