Hi,

I experienced the same problem. I found an earlier ticket on this same 
error and reopened it. See http://code.djangoproject.com/ticket/2130
The fix you suggested fixes the problem for me. I've added it to the 
comments of the ticket.

 - Haavikko

apramanik wrote:
> Anyone? I still haven't gotten this to work without modifying Django.
> Thanks!
>
> On Jan 12, 3:34 pm, apramanik <[EMAIL PROTECTED]> wrote:
>   
>> It seems to be fixed if I change sql_create django/core/management/
>> sql.py to
>>
>>     for model in app_models:
>>         output, references = sql_model_create(model, style,
>> known_models)
>>         final_output.extend(output)
>>         for refto, refs in references.items():
>>             pending_references.setdefault(refto, []).extend(refs)
>>         #ADD
>>         for known_model in known_models:
>>
>> final_output.extend(sql_for_pending_references(known_model, style,
>> pending_references))
>>         #END ADD
>>         # Keep track of the fact that we've created the table for this
>> model.
>>         known_models.add(model)
>>
>> It didn't make sense to pass in model to sql_for_pending_references.
>>
>> On Jan 12, 2:21 pm, apramanik <[EMAIL PROTECTED]> wrote:
>>
>>     
>>> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to