#12421: Foreign Key on Non-Primary Field fails due to lack of Index on Related
Field w/ MySQL
---------------------------------------------------+------------------------
          Reporter:  anonymous                     |         Owner:  nobody
            Status:  closed                        |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  SVN   
        Resolution:  worksforme                    |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  0     
        Needs_docs:  0                             |   Needs_tests:  0     
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by ramiro):

  * status:  new => closed
  * resolution:  => worksforme

Comment:

 I tset this (using a `t12421` app) and MySQL 5.0 by creating only the
 `Relation` model, the sqlall output shows the index is correctly being
 created:

 {{{
 r...@host:~/src/dtest08$ PYTHONPATH=~/django/trunk ./manage.py sqlall t12421
 BEGIN;
 CREATE TABLE `relation_codes` (
     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
     `code` varchar(2) NOT NULL
 )
 ;
 CREATE INDEX `relation_codes_code` ON `relation_codes` (`code`);
 COMMIT;
 }}}

 The index is being created.

 I suspect you might have added the `db_index=True` to the `code` field of
 `Relation` after the `relation_codes` table was created. Remember `syncdb`
 works with a model-level granularity to create tables; if you need you
 will need to devise or use a third-party schema migration tool.

 Another probable (although a weird one )reason for the index not being
 present is if MySQL isn't creating it even if is is being told to do so.
 But we 'd need more details about the setup.

 Closing this as worksforme. Please reopen if you can provide more details
 and a a detailed sequence to reproduce this, or if I missed something.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12421#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en.

Reply via email to