#32672: Primary Key, type double and type unsigned integer ain't detected
correctly
for Sqlite3 Database
-------------------------------------+-------------------------------------
Reporter: jgr88 | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SQLite3 PrimaryKey | Triage Stage: Accepted
Datatypes |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Looks like you forgot to strip leading and trailing quotes,
`Identifier.get_real_name()` does that
{{{#!diff
diff --git a/django/db/backends/sqlite3/introspection.py
b/django/db/backends/sqlite3/introspection.py
index f109b5d5ee..983c000e8b 100644
--- a/django/db/backends/sqlite3/introspection.py
+++ b/django/db/backends/sqlite3/introspection.py
@@ -214,12 +214,15 @@ def get_primary_key_column(self, cursor,
table_name):
if table_type == 'view':
# Views don't have a primary key.
return None
- fields_sql = create_sql[create_sql.index('(') +
1:create_sql.rindex(')')]
- for field_desc in fields_sql.split(','):
- field_desc = field_desc.strip()
- m = re.match(r'(?:(?:["`\[])(.*)(?:["`\]])|(\w+)).*PRIMARY
KEY.*', field_desc)
- if m:
- return m[1] if m[1] else m[2]
+ latest_identifier = None
+ fields = sqlparse.parse(create_sql)[0].tokens[-1]
+ for index, token in enumerate(fields):
+ if isinstance(token, sqlparse.sql.Identifier):
+ latest_identifier = token
+ continue
+ elif (token.match(sqlparse.tokens.Keyword, 'PRIMARY') and
+
fields.token_next(index)[1].match(sqlparse.tokens.Keyword, 'KEY')):
+ return latest_identifier.get_real_name()
return None
def _get_foreign_key_constraints(self, cursor, table_name):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32672#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/073.076b9476952d9b890b14c847f5614e6b%40djangoproject.com.