yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Wrong type mapping for SQLite unsigned primary key #17960

Closed bizley closed 4 years ago

bizley commented 4 years ago

What steps will reproduce the problem?

use yii\db\SchemaBuilderTrait;

$this->getDb()
    ->createCommand()
    ->createTable(
        'table',
        ['id' => $this->primaryKey()->unsigned()]
    )
    ->execute();

What is the expected result?

Table created.

What do you get instead?

yii\db\Exception : SQLSTATE[HY000]: General error: 1 AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY Failed to prepare SQL: CREATE TABLE unsigned_pk ( id integer UNSIGNED PRIMARY KEY AUTOINCREMENT NOT NULL )

Additional info

Q A
Yii version 2.0.*
PHP version *
Operating system *

We could get away with it by setting it like this

public $typeMap = [
    Schema::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
    Schema::TYPE_UPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
    // instead of Schema::TYPE_UPK => 'integer UNSIGNED PRIMARY KEY AUTOINCREMENT NOT NULL',
    Schema::TYPE_BIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
    Schema::TYPE_UBIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
    // instead of Schema::TYPE_UBIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
    // ...
];

OR by remowing AUTOINCREMENT from unsigned mappings but I'm not sure what is more important to keep for the developer.

samdark commented 4 years ago

New mappings look a bit better. How about a pull request?

bizley commented 4 years ago

Sure thing.