1

up()Yii を使用して移行を行い、メソッドで新しいテーブルを作成しようとしています。ENGINE=InnoDB句を追加しない限り、正常に動作します。その場合、エラーが発生しますnear ENGINE

public function up()
{
    $this->createTable('tbl_project', array(
        'id' => 'pk',
        'name' => 'string NOT NULL',
        'description' => 'text NOT NULL',
        'create_time' => 'datetime DEFAULT NULL',
        'create_user_id' => 'int(11) DEFAULT NULL',
        'update_time' => 'datetime DEFAULT NULL',
        'update_user_id' => 'int(11) DEFAULT NULL',
    ), 'ENGINE=InnoDB');
}

私の Yii のバージョンは 1.1.12 です。PHP 5.4.3、MySQL 5.5.24。

それはYiiのバグですか?

編集 (yii バグの説明):

*** applying m130208_133533_create_table_project
> create table tbl_project ...exception 'CDbException' with message 'CDbComm
and failed to execute the SQL statement: CDbCommand failed to prepare the SQL st
atement: SQLSTATE[HY000]: General error: 1 near "engine": syntax error. The SQL
statement executed was: CREATE TABLE 'tbl_project' (
    "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    "name" varchar(255) NOT NULL,
    "description" text NOT NULL,
    "create_time" datetime DEFAULT NULL,
    "create_user_id" int(11) DEFAULT NULL,
    "update_time" datetime DEFAULT NULL,
    "update_user_id" int(11) DEFAULT NULL
) engine = InnoDB' in C:\wamp\yii\framework\db\CDbCommand.php:357
4

4 に答える 4

8

私は同じ問題を抱えていましたが、console.php と main.php のデータベースの構成が同じであることを確認することで解決しました

i.e 'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=databasename',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => 'ur password',
        'charset' => 'utf8',
    ),

両方のファイルの sqlite 行にコメントを付けます

于 2013-02-24T18:40:11.130 に答える
4

コンソール コマンドである「protected\yiic\migrate」を使用すると、protected\config\console.php が使用されるため、その「db」コンポーネントを適切に構成する必要があります (protected\config\main.php が構成されているため)。InnoDB エラーが発生した場合は、まだ SQLite 用に構成されている可能性があります。

于 2014-06-08T20:20:53.733 に答える
0

試す:

$this->createTable('tbl_project', array(
        'id' => 'pk',
        'name' => 'string NOT NULL',
        'description' => 'text NOT NULL',
        'create_time' => 'datetime DEFAULT NULL',
        'create_user_id' => 'int(11) DEFAULT NULL',
        'update_time' => 'datetime DEFAULT NULL',
        'update_user_id' => 'int(11) DEFAULT NULL',
    ), 
    'engine = InnoDB'
);

うまくいかない場合は、MySql エラーを表示してください

于 2013-02-08T15:11:07.487 に答える