Django get alter table commands for a module

微笑、不失礼 提交于 2019-12-24 19:33:39

问题


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;

回答1:


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



来源:https://stackoverflow.com/questions/11776386/django-get-alter-table-commands-for-a-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!