简体   繁体   English

Django 1.6.5中的Syncdb命令不会在models.py中创建新的模型类-说表已经存在

[英]Syncdb command in Django 1.6.5 does not create new model class in models.py - says table already exists

I am following a tutorial on Udemy on Django, in which the author adds a new model to models.py and runs the syncdb command to add the table to the database. 我正在关注有关Django上的Udemy的教程,其中作者在model.py中添加了新模型,并运行syncdb命令将表添加到数据库中。 I am trying to replicate this using Django 1.6.5 and MySQL 5.5. 我正在尝试使用Django 1.6.5和MySQL 5.5复制此代码。 I have searched other questions and they are slightly different scenarios. 我搜索了其他问题,它们的情况略有不同。

I read in the docs that you can add new models using syncdb, but you will either have to drop the existing tables or use South to migrate the data to alter an existing table. 我在文档中读到可以使用syncdb添加新模型,但是您要么必须删除现有表,要么使用South迁移数据以更改现有表。 I am simply trying to add a new model, and I get the error -- the table already exists. 我只是试图添加一个新模型,但出现错误-该表已存在。

Could someone explain why I am getting this error, and should I just use South and avoid this situation? 有人可以解释为什么我会收到此错误,我应该只使用South来避免这种情况吗?

Once you've created the DB, you can't simply add new models. 创建数据库后,就不能简单地添加新模型。

In order to update your schema, you'll have to use south (for migrations in Django <= 1.6), or use the built-in migrations in Django 1.7 为了更新您的架构,您将必须使用south(在Django <= 1.6中进行迁移),或在Django 1.7中使用内置的迁移

Since you're using Django 1.6, you should read about it in http://south.readthedocs.org/en/latest/tutorial/part1.html and then use the package to migrate your schema. 由于您使用的是Django 1.6,因此您应该在http://south.readthedocs.org/en/latest/tutorial/part1.html中阅读有关Django的内容,然后使用该软件包来迁移您的架构。

Just follow the tutorial and ask on Stack Overflow if further questions rise, it shouldn't be too complicated 只需按照教程进行,并在Stack Overflow上询问是否还有其他问题,应该不会太复杂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM