【问题标题】:Yii: CDbException' with message 'CDbCo mmand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statementYii: CDbException' with message 'CDbCo mmand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement
【发布时间】:2014-01-31 20:04:33
【问题描述】:

我是 Yii 新手,我尝试使用“yiic migrate”命令设置数据库。

我的迁移如下所示:

<?php

class m140131_054313_crear_base_de_datos extends CDbMigration
{
public function up()
{
    $this->createTable('tbl_proveedor', array(
        'id' => 'pk',
        'nombre' => 'string NOT NULL',
        'telefono' => 'text NULL',
        'direccion' => 'text DEFAULT NULL',
        'pagina' => 'text DEFAULT NULL',
        'fecha_ingreso' => 'datetime DEFAULT NULL',
        'usuario_creacion' => 'int(11) DEFAULT NULL',
    ), 'ENGINE=InnoDB');
}
...

但我在提示中收到此错误:

Yii Migration Tool v1.0 (based on Yii v1.1.14)

Total 1 new migration to be applied:
    m140131_054313_crear_base_de_datos

Apply the above migration? (yes|no) [no]:y
*** applying m140131_054313_crear_base_de_datos
    > create table tbl_proveedor ...exception 'CDbException' with message 'CDbCo
mmand failed to execute the SQL statement: CDbCommand failed to prepare the SQL
statement: SQLSTATE[HY000]: General error: 1 near "ENGINE": syntax error. The SQ
L statement executed was: CREATE TABLE 'tbl_proveedor' (
        "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
        "nombre" varchar(255) NOT NULL,
        "telefono" text NULL,
        "direccion" text DEFAULT NULL,
        "pagina" text DEFAULT NULL,
        "fecha_ingreso" datetime DEFAULT NULL,
        "usuario_creacion" int(11) DEFAULT NULL
) ENGINE=InnoDB' in C:\xampp\htdocs\yii\framework\db\CDbCommand.php:358
...

你有什么建议吗?

非常感谢。

【问题讨论】:

  • 你能告诉我你在 main.php 文件中使用什么配置吗?
  • 我的意思是数据库组件
  • 我已经为 MySQL 配置了它

标签: yii yiic


【解决方案1】:

此迁移应用于 SQLite 数据库,并且该引擎不是语言构造。

您可能遇到的错误是您有不同的控制台应用配置,它引用了生成的 SQLite 数据库。

确保您在控制台中有类似的内容:

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

【讨论】:

  • 但是你有正确的文件吗?尝试编辑为无效值,然后查看迁移是否有效。如果有效,则意味着仍然连接到 SQLite,并且您的配置不正确。
  • 是的!就是这样。我配置了main.php,但我必须将配置添加到console.php。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-22
  • 2023-03-17
  • 1970-01-01
  • 2013-07-13
  • 2022-12-27
  • 2016-08-30
  • 1970-01-01
相关资源
最近更新 更多