2

I am new with Yii and I tried to set up a database using the "yiic migrate" command.

My migration looks like this:

<?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');
}
...

But I get this error in the prompt:

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
...

Do you have any suggestion?

Thank you very much.

Allfarid Morales García
  • 1,455
  • 2
  • 17
  • 27

1 Answers1

0

This migration is applied on the SQLite database, and there the engine is not a language construct.

The error you might have is that you have different config for console apps, that references the SQLite database, which was generated.

Make sure you have in console something like:

'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=databasename',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => 'ur password',
        'charset' => 'utf8',
    ),
Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • But do you have in the correct file? Try editing into invalid value and see if the migration works then. If works, it means still connects to SQLite and your config is not OK. – Pentium10 Feb 01 '14 at 08:07
  • 1
    Yes! That was it. I configurated main.php, but I had to add the config to console.php. Thank you very much. – Allfarid Morales García Feb 02 '14 at 05:07