Django获取模块的alter table命令 [英] Django get alter table commands for a module
问题描述
我已经添加了一个新的字段到我的模型。从django manage.py我如何打印迁移(alter table语句)。在以下is_tag是我的新字段
当我做sqlall时,我得到以下输出。我如何得到alter table命令$ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ :/ opt / labs / labs_site#python manage.py sqlall content
BEGIN;
CREATE TABLE`content_content`(
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(255)NOT NULL,
`uploaded_by_id` integer NOT NULL,
`is_local` integer NOT NULL,
`access` integer NOT NULL,
`fq_name` varchar(255)NOT NULL,
`description` longtext NOT NULL,
`is_tag` bool NOT NULL,
`timestamp` datetime NOT NULL
)
;
ALTER TABLE`content_content` ADD CONSTRAINT`uploaded_by_id_refs_id_4f9cfefd` FOREIGN KEY(`uploaded_by_id`)参考`users_userprofile`(`id`);
CREATE INDEX`content_content_1bc5ce19` ON`content_content`(`uploaded_by_id`);
COMMIT;
syncdb
永远不会更改表或文档自己的话:
syncdb只会为尚未安装的模型创建表。它将永远不会发出ALTER TABLE语句以匹配安装后对模型类所做的更改。对模型类和数据库模式的更改通常涉及某种形式的歧义,在这种情况下,Django将不得不猜测正确的变化。在这个过程中有一个关键数据丢失的风险。
要管理迁移,您应该使用南
I have added a new field to my models .From django manage.py how can i print the migration(alter table statement).In the following is_tag is my new field
When i do sqlall i get the following output.How can i get the alter table commands
root@rajeev-laptop:/opt/labs/labs_site# python manage.py sqlall content
BEGIN;
CREATE TABLE `content_content` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(255) NOT NULL,
`uploaded_by_id` integer NOT NULL,
`is_local` integer NOT NULL,
`access` integer NOT NULL,
`fq_name` varchar(255) NOT NULL,
`description` longtext NOT NULL,
`is_tag` bool NOT NULL,
`timestamp` datetime NOT NULL
)
;
ALTER TABLE `content_content` ADD CONSTRAINT `uploaded_by_id_refs_id_4f9cfefd` FOREIGN KEY (`uploaded_by_id`) REFERENCES `users_userprofile` (`id`);
CREATE INDEX `content_content_1bc5ce19` ON `content_content` (`uploaded_by_id`);
COMMIT;
syncdb
will never alter tables, or in the docs own words:
syncdb will only create tables for models which have not yet been installed. It will never issue ALTER TABLE statements to match changes made to a model class after installation. Changes to model classes and database schemas often involve some form of ambiguity and, in those cases, Django would have to guess at the correct changes to make. There is a risk that critical data would be lost in the process.
To manage migrations, you should use South
这篇关于Django获取模块的alter table命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!