﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15933	mysql inspectdb loosing primary_key information	andi	Anssi Kääriäinen	"I've been inspecting a mysql 4 (4.0.16-standard) database. The resulting models file didn't handle all the primary_keys right if the primary key column is used in any other key.

Example table layout:
{{{
CREATE TABLE `test` (
  `PrimaryKeyColumn` int(10),
  `AnotherColumn`    int(10),
  `SomethingElse`    int(10),
  PRIMARY KEY `PrimaryKeyColumn`,
  UNIQUE KEY `AnotherKey` (`PrimaryKeyColumn`,`AnotherColumn`)
);
}}}
The {{{SHOW INDEX FROM %s}}} query would return the following table:
{{{
mysql> show index from test;                                                                                                                                                    
+-------+------------+------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name   | Seq_in_index | Column_name      | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+
| test  |          0 | PRIMARY    |            1 | PrimaryKeyColumn | A         |           0 |     NULL | NULL   |      | BTREE      |         | 
| test  |          0 | AnotherKey |            1 | PrimaryKeyColumn | A         |        NULL |     NULL | NULL   |      | BTREE      |         | 
| test  |          0 | AnotherKey |            2 | AnotherColumn    | A         |        NULL |     NULL | NULL   | YES  | BTREE      |         | 
+-------+------------+------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+
}}}
After reading row 2 the primary_key information would be lost.
To preserve this information i added a check to only update the {{{unique}}} field. Patch is attached.

I had to apply #14618 to use inspectdb with my mysql version."	Bug	closed	Core (Management commands)	1.3	Normal	fixed	inspectdb mysql	andi	Accepted	1	0	1	0	0	0
