I'm going through the Django tutorial and am defining the poll and choice models. When I run manage.py sql polls to see the sql statements, I get:
CREATE TABLE `polls_poll` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`question` varchar(200) NOT NULL,
`pub_date` datetime NOT NULL
);
CREATE TABLE `polls_choice` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`poll_id` integer NOT NULL,
`choice_text` varchar(200) NOT NULL,
`votes` integer NOT NULL
);
ALTER TABLE `polls_choice` ADD CONSTRAINT `poll_id_refs_id_3aa09835`
FOREIGN KEY (`poll_id`) REFERENCES `polls_poll` (`id`);
Why does Django use an ALTER statement when applying the Foreign Key instead of doing it in the Create table statement? Something like the following seems more succinct:
`poll_id integer NOT NULL REFERENCES polls_choice(id)`