Closed elonzh closed 6 years ago
peewee version: 3.2.2 database: mysql 5.6
i changed the sql to
CREATE TABLE IF NOT EXISTS `trial_books` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `created_at` DATETIME NOT NULL, `updated_at` DATETIME NOT NULL, `book_id` INTEGER UNSIGNED NOT NULL, FOREIGN KEY (`
book_id`) REFERENCES `books` (`id`))
``
it works.
that is, ``book_id` INTEGER NOT NULL UNSIGNED` is a wrong sql for mysql
column_definition:
data_type [NOT NULL | NULL] [DEFAULT default_value]
[AUTO_INCREMENT] [UNIQUE [KEY]] [[PRIMARY] KEY]
[COMMENT 'string']
[COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
[STORAGE {DISK|MEMORY|DEFAULT}]
[reference_definition]
data_type:
BIT[(length)]
| TINYINT[(length)] [UNSIGNED] [ZEROFILL]
| SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
| MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
| INT[(length)] [UNSIGNED] [ZEROFILL]
| INTEGER[(length)] [UNSIGNED] [ZEROFILL]
| BIGINT[(length)] [UNSIGNED] [ZEROFILL]
| REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
| DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
| FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
| DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL]
| NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL]
| DATE
| TIME[(fsp)]
| TIMESTAMP[(fsp)]
| DATETIME[(fsp)]
| YEAR
| CHAR[(length)]
[CHARACTER SET charset_name] [COLLATE collation_name]
| VARCHAR(length)
[CHARACTER SET charset_name] [COLLATE collation_name]
| BINARY[(length)]
| VARBINARY(length)
| TINYBLOB
| BLOB[(length)]
| MEDIUMBLOB
| LONGBLOB
| TINYTEXT
[CHARACTER SET charset_name] [COLLATE collation_name]
| TEXT[(length)]
[CHARACTER SET charset_name] [COLLATE collation_name]
| MEDIUMTEXT
[CHARACTER SET charset_name] [COLLATE collation_name]
| LONGTEXT
[CHARACTER SET charset_name] [COLLATE collation_name]
| ENUM(value1,value2,value3,...)
[CHARACTER SET charset_name] [COLLATE collation_name]
| SET(value1,value2,value3,...)
[CHARACTER SET charset_name] [COLLATE collation_name]
| spatial_type
You're probably best off creating your own field type.
class UnsignedIntegerField(IntegerField):
field_type = 'INTEGER UNSIGNED'
I have some models based on the database which was created by sql. here is ddl for the model
Book
:and the model
Book
:now we need a new model
TrialBook
:we added
UNSIGNED
forTrialBook.id
because the ddl ofBook.id
isUNSIGNED
.but when we got a syntax error like that:
ddl for
TrialBook
: