#31846: MySQL inspectdb doesn't handle composite keys
-------------------------------------+-------------------------------------
     Reporter:  François Poulain     |                    Owner:  (none)
         Type:  New feature          |                   Status:  closed
    Component:  Core (Management     |                  Version:  3.0
  commands)                          |
     Severity:  Normal               |               Resolution:  duplicate
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

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


Comment:

 As far as I'm aware `KEY` is not a synonym of `PRIMARY KEY` it's also not
 recognized as a primary key:
 {{{
 mysql> CREATE TABLE `feedapi_stat` (
     ->     `id` int(10) unsigned NOT NULL DEFAULT 0,
     ->     `type` varchar(64) NOT NULL,
     ->     `timestamp` int(11) NOT NULL,
     ->     `time` varchar(20) NOT NULL,
     ->     `value` int(11) NOT NULL,
     ->      KEY `id` (`id`,`type`,`timestamp`,`time`));
 mysql>desc feedapi_stat;
 +-----------+--------------+------+-----+---------+-------+
 | Field     | Type         | Null | Key | Default | Extra |
 +-----------+--------------+------+-----+---------+-------+
 | id        | int unsigned | NO   | MUL | 0       |       |
 | type      | varchar(64)  | NO   |     | NULL    |       |
 | timestamp | int          | NO   |     | NULL    |       |
 | time      | varchar(20)  | NO   |     | NULL    |       |
 | value     | int          | NO   |     | NULL    |       |
 +-----------+--------------+------+-----+---------+-------+
 mysql> CREATE TABLE `feedapi_stat2` (
     ->     `id` int(10) unsigned NOT NULL DEFAULT 0,
     ->     `type` varchar(64) NOT NULL,
     ->     `timestamp` int(11) NOT NULL,
     ->     `time` varchar(20) NOT NULL,
     ->     `value` int(11) NOT NULL,
     ->      PRIMARY KEY `id` (`id`,`type`,`timestamp`,`time`));
 +-----------+--------------+------+-----+---------+-------+
 | Field     | Type         | Null | Key | Default | Extra |
 +-----------+--------------+------+-----+---------+-------+
 | id        | int unsigned | NO   | PRI | 0       |       |
 | type      | varchar(64)  | NO   | PRI | NULL    |       |
 | timestamp | int          | NO   | PRI | NULL    |       |
 | time      | varchar(20)  | NO   | PRI | NULL    |       |
 | value     | int          | NO   |     | NULL    |       |
 +-----------+--------------+------+-----+---------+-------+
 }}}
 ----
 Also, composite primary keys are handled by `inspectdb` since
 295249c901e13ec1703ada5c414cd97aba72f3e9, so IMO we can close it as a
 duplicate:
 {{{
 $ python manage.py inspectdb
 ...
 class FeedapiStat2(models.Model):
     id = models.PositiveIntegerField(primary_key=True)  # The composite
 primary key (id, type, timestamp, time) found, that is not supported. The
 first column is selected.
     type = models.CharField(max_length=64)
     timestamp = models.IntegerField()
     time = models.CharField(max_length=20)
     value = models.IntegerField()

     class Meta:
         managed = False
         db_table = 'feedapi_stat2'
         unique_together = (('id', 'type', 'timestamp', 'time'),)
 }}}

 Duplicate of #32234.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31846#comment:10>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701817177414c-659da3a0-07c2-458e-9eb8-057fd4cce3e5-000000%40eu-central-1.amazonses.com.

Reply via email to