问题
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