0

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;
Rajeev
  • 44,985
  • 76
  • 186
  • 285

1 Answers1

2

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

Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • But i never said that i want to use syncdb.I want the python manage.py command to give me the alter statements.. – Rajeev Aug 04 '12 at 16:06
  • It can't as there's no logic there to generate the required ALTER statment. The ALTER statement you are seeing in `sqlall` is just the initial sql needed to get the tables setup. From the docs, sqlall: `Prints the CREATE TABLE and initial-data SQL statements for the given app name(s).` – Timmy O'Mahony Aug 04 '12 at 16:08