Well inserting rows with invalid poll_id's works, until i enter the
ALTER TABLE by hand, so the foreign key constraints are definitely not
there.
Anyways, here's what it outputs:
BEGIN;
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` varchar(200) NOT NULL,
`votes` integer NOT NULL
)
;
-- The following references should be added but depend on non-existent
tables:
-- ALTER TABLE `polls_choice` ADD CONSTRAINT poll_id_refs_id_5d896c23
FOREIGN KE
Y (`poll_id`) REFERENCES `polls_poll` (`id`);
CREATE INDEX `polls_choice_poll_id` ON `polls_choice` (`poll_id`);
COMMIT;
On Jan 12, 2:11 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Do manage.py sqlall polls instead, it will show all the sql, not just
> the tables,
>
> On Jan 12, 3:41 pm, apramanik <[EMAIL PROTECTED]> wrote:
>
> > Hi all,
>
> > I'm trying out the Django development version and have been going
> > through the tutorial, but the models aren't creating foreign keys.
>
> > When I run 'python manage.py sql polls' I get:
>
> > BEGIN;
> > 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` varchar(200) NOT NULL,
> > `votes` integer NOT NULL
> > )
> > ;
> > -- The following references should be added but depend on non-existent
> > tables:
> > -- ALTER TABLE `polls_choice` ADD CONSTRAINT poll_id_refs_id_5d896c23
> > FOREIGN KE
> > Y (`poll_id`) REFERENCES `polls_poll` (`id`);
> > COMMIT;
>
> > Notice the weird message at the bottom, 'polls_choice' does exist!
>
> > models.py:
>
> > class Poll(models.Model):
>
> > question = models.CharField(max_length=200)
> > pub_date = models.DateTimeField('date published')
>
> > def __unicode__( self ) :
> > return self.question
>
> > def wasPublishedToday( self ) :
> > return self.pub_date.date() == datetime.date.today()
>
> > class Choice(models.Model):
>
> > poll = models.ForeignKey(Poll)
> > choice = models.CharField(max_length=200)
> > votes = models.IntegerField()
>
> > def __unicode__( self ) :
> > return self.choice
>
> > settings.py:
>
> > DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql',
> > 'mysql', 'sqlite3' or 'oracle'.
> > DATABASE_NAME = 'mysite' # Or path to database file if using
> > sqlite3.
> > DATABASE_USER = 'root' # Not used with sqlite3.
> > DATABASE_HOST = '' # Set to empty string for localhost.
> > Not used with sqlite3.
> > DATABASE_PORT = '' # Set to empty string for default. Not
> > used with sqlite3.
> > DATABASE_OPTIONS = {
> > "init_command" : "SET storage_engine = INNODB",
>
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---