Model schema column type mismatches
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
| Cinder |
Undecided
|
Mate Lakat |
Bug Description
I ran through a script that uses sqlalchemy's metadata.create_all to make the database, and found out that some column's types are not matching the database type.
Briefly what I have done is tried to create the database with BASE.metadata.
Here are the steps to
To repro with PostgreSQL:
drop database if exists cinder;
create database cinder with encoding 'utf-8';
grant all on DATABASE cinder to matelakat;
I installed dbbuild (https:/
and then:
dbbuild postgresql:
...
sqlalchemy.
DETAIL: Key columns "group_type_id" and "id" are of incompatible types: integer and character varying.
[SQL: '\nCREATE TABLE group_type_projects (\n\tcreated_at TIMESTAMP WITHOUT TIME ZONE, \n\tupdated_at TIMESTAMP WITHOUT TIME ZONE, \n\tdeleted_at TIMESTAMP WITHOUT TIME ZONE, \n\tid SERIAL NOT NULL, \n\tgroup_type_id INTEGER NOT NULL, \n\tproject_id VARCHAR(255), \n\tdeleted INTEGER, \n\tPRIMARY KEY (id), \n\tCONSTRAINT uniq_group_
So fixed that, and re-run:
sqlalchemy.
DETAIL: Key columns "volume_type_id" and "id" are of incompatible types: integer and character varying.
[SQL: '\nCREATE TABLE volume_
NOT NULL, \n\tvolume_type_id INTEGER NOT NULL, \n\tproject_id VARCHAR(255), \n\tdeleted INTEGER, \n\tPRIMARY KEY (id), \n\tCONSTRAINT uniq_volume_
So fixed that one as well.
Here is the patch:
diff --git a/cinder/
index f091780a9.
--- a/cinder/
+++ b/cinder/
@@ -418,7 +418,7 @@ class VolumeTypeProje
)
id = Column(Integer, primary_key=True)
- volume_type_id = Column(Integer, ForeignKey(
+ volume_type_id = Column(String, ForeignKey(
project_id = Column(String(255))
deleted = Column(Integer, default=0)
@@ -440,7 +440,7 @@ class GroupTypeProjec
)
id = Column(Integer, primary_key=True)
- group_type_id = Column(Integer, ForeignKey(
+ group_type_id = Column(String, ForeignKey(
project_id = Column(String(255))
deleted = Column(Integer, default=0)
I re-created the database with migrations to see what the type of the columns is:
cinder=# \d volume_
Column | Type | Modifiers
-------
id | integer | not null default nextval(
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
deleted_at | timestamp without time zone |
volume_type_id | character varying(36) |
project_id | character varying(255) |
deleted | integer |
Indexes:
"volume_
"volume_
Foreign-key constraints:
"volume_
That seems to be correct (see that volume_type_id is varchar)
The other table:
cinder=# \d group_type_
Column | Type | Modifiers
-------
id | integer | not null default nextval(
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
deleted_at | timestamp without time zone |
group_type_id | character varying(36) |
project_id | character varying(255) |
deleted | boolean |
Indexes:
"group_
"group_
Foreign-key constraints:
"group_
This is correct as well, see that group_type_id is varchar 36
The same with MYSQL:
MariaDB [cinder]> describe volume_
+------
| Field | Type | Null | Key | Default | Extra |
+------
| id | int(11) | NO | PRI | NULL | auto_increment |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| deleted_at | datetime | YES | | NULL | |
| volume_type_id | varchar(36) | YES | MUL | NULL | |
| project_id | varchar(255) | YES | | NULL | |
| deleted | int(11) | YES | | NULL | |
+------
7 rows in set (0.00 sec)
MariaDB [cinder]> describe group_type_
+------
| Field | Type | Null | Key | Default | Extra |
+------
| id | int(11) | NO | PRI | NULL | auto_increment |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| deleted_at | datetime | YES | | NULL | |
| group_type_id | varchar(36) | YES | MUL | NULL | |
| project_id | varchar(255) | YES | | NULL | |
| deleted | tinyint(1) | YES | | NULL | |
+------
7 rows in set (0.00 sec)
Changed in cinder: | |
assignee: | nobody → Mate Lakat (mate-lakat) |
status: | New → In Progress |
Reviewed: https:/
Committed: https:/
Submitter: Jenkins
Branch: master
commit 6d1036f7e7fc4b9
Author: Mate Lakat <email address hidden>
Date: Wed Mar 8 15:59:03 2017 +0100
Fix column types in models.py
Some columns' type were not matching the one in the database. Not sure
if that causes any issues, but it's worth to fix the issue.
Closes-Bug: #1671135
Change-Id: Idb242d4f1eb469
Changed in cinder: | |
status: | In Progress → Fix Released |
This issue was fixed in the openstack/cinder 11.0.0.0b1 development milestone.
Fix proposed to branch: master /review. openstack. org/443165
Review: https:/