python-django框架根据模型不能新建表

ningyougang 2014-09-09 05:12:07
然后在含有manae.py里执行 python manage.py sql polls(其中polls为1个app,里面的models.py有其模型定义语句),报错
CommandError: App 'polls' has migrations. Only the sqlmigrate and sqlflush commands can be used when an app has migrations.
请问如何解决
...全文
6019 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿凯99 2015-02-04
  • 打赏
  • 举报
回复
老版本只要已经写好连接语句,只要把注释取消就能连接。新版本要自己去看看how to 。
feibinyang 2015-02-03
  • 打赏
  • 举报
回复
1.8 版本: 然后:python manage.py sqlmigrate polls 0001
引用 8 楼 feibinyang 的回复:
1.6 版本: python manage.py sql polls 1.8版本: python manage.py makemigrations polls 亲自试过,有效的。
引用 8 楼 feibinyang 的回复:
1.6 版本: python manage.py sql polls 1.8版本: python manage.py makemigrations polls 亲自试过,有效的。
引用 8 楼 feibinyang 的回复:
1.6 版本: python manage.py sql polls 1.8版本: python manage.py makemigrations polls 亲自试过,有效的。
feibinyang 2015-02-03
  • 打赏
  • 举报
回复
1.6 版本: python manage.py sql polls 1.8版本: python manage.py makemigrations polls 亲自试过,有效的。
王羽菲 2015-01-08
  • 打赏
  • 举报
回复
引用 5 楼 lidonghit 的回复:
删除polls文件夹下的migrations文件夹
我根据您说的方法,已经成功了。十分感谢
风之水2003 2014-09-26
  • 打赏
  • 举报
回复
The migrate command takes all the migrations that haven’t been applied (Django tracks which ones are applied using a special table in your database called django_migrations) and runs them against your database - essentially, synchronizing the changes you made to your models with the schema in the database. Migrations are very powerful and let you change your models over time, as you develop your project, without the need to delete your database or tables and make new ones - it specializes in upgrading your database live, without losing data. We’ll cover them in more depth in a later part of the tutorial, but for now, remember the three-step guide to making model changes: Change your models (in models.py). Run python manage.py makemigrations to create migrations for those changes Run python manage.py migrate to apply those changes to the database. 最后这个3个步骤,你试试,看看是否可以达到python manage.py sql/syncdb的效果
  • 打赏
  • 举报
回复
删除polls文件夹下的migrations文件夹
The_Third_Wave 2014-09-10
  • 打赏
  • 举报
回复
新版本和老版本确实有区别的,建议楼主降级到1.6,或者使用最新的demo,仔细看下更新的东西。
ningyougang 2014-09-10
  • 打赏
  • 举报
回复
引用 1 楼 u013171165 的回复:
版本不对?1.6和1.8有点区别
官网上下的Django-1.7.tar.gz。python版本为2.7.7
juanmaoking 2014-09-10
  • 打赏
  • 举报
回复
django1.7后感觉建立数据库链接方式不同了,今天也遇到了
D:\python_ex_yiyu\django_ex_yiyu\djangobook\djangobook>python manage.py makemigrations book
Migrations for 'book':
0001_initial.py:
- Create model Author
- Create model Book
- Create model Publisher
- Add field publisher to book


D:\python_ex_yiyu\django_ex_yiyu\djangobook\djangobook> python manage.py sqlmigrate book 0001
BEGIN;
CREATE TABLE "book_author" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(30) NOT NULL, "last_name" varchar(40) NOT NULL, "email" varchar(75) NOT NULL);
CREATE TABLE "book_book" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "title" varchar(100) NOT NULL, "publication_date" date NOT NULL);
CREATE TABLE "book_book_authors" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "book_id" integer NOT NULL REFERENCES "book_book" ("id"), "author_id" integer NOT NULL REFERENCES "book_author" ("id"), UNIQUE ("book_id", "author_id"));
CREATE TABLE "book_publisher" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(30) NOT NULL, "address" varchar(50) NOT NULL, "city" varchar(60) NOT NULL, "state_province" varchar(30) NOT NULL, "country" varchar(50) NOT NULL, "website" varchar(200) NOT NULL
);
CREATE TABLE "book_book__new" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "title" varchar(100) NOT NULL, "publication_date" date NOT NULL, "publisher_id" integer NOT NULL REFERENCES "book_publisher" ("id"));
INSERT INTO "book_book__new" ("publication_date", "id", "title") SELECT "publication_date", "id", "title" FROM "book_book";
DROP TABLE "book_book";
ALTER TABLE "book_book__new" RENAME TO "book_book";
CREATE INDEX book_book_2604cbea ON "book_book" ("publisher_id");

COMMIT;


具体看下官方文档
https://docs.djangoproject.com/en/1.7/intro/tutorial01/#activating-models

The_Third_Wave 2014-09-09
  • 打赏
  • 举报
回复
版本不对?1.6和1.8有点区别

37,742

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧