SQLSTATE[HY000]: General error: 1 no such table: when running Migration on SQLITE with Yii2

Asked

Viewed 746 times

0

I am using yii2 for a small project, I am using sqlite to persist the data. And here is where the problem is occurring. Any table I create in sqlite yii2 does not recognize, nor does using GII to create models. Interesting is that it connects in the database correctly. I created the table with a Migration.

PDO for sqlite is active.

Yii configuration file:

 return [
          'class' => 'yii\db\Connection',
          'dsn'=>'sqlite:portaltransporte.db',
          'username' => '',
          'password' => '',
          'charset' => 'utf8',

          // Schema cache options (for production environment)
         //'enableSchemaCache' => true,
        //'schemaCacheDuration' => 60,
       //'schemaCache' => 'cache',
    ];

Code of the Migration:

<?php

  use yii\db\Migration;
  use yii\db\Schema;    
   class m181207_172303_tabela_contrato extends Migration
   {
      /**
     * {@inheritdoc}
     */
      public function safeUp()
      {
         $this->createTable('contrato',[
            'id'    =>Schema::TYPE_PK,
            'url'   =>Schema::TYPE_STRING .'NOT NULL',
            'post'  =>Schema::TYPE_STRING,
            'get'   =>Schema::TYPE_STRING,
            'put'   =>Schema::TYPE_STRING,
            'base'  =>Schema::TYPE_STRING,  
          ]);

      }

      /**
      * {@inheritdoc}
      */
       public function safeDown()
       {
          echo "m181207_172303_tabela_contrato cannot be reverted.\n";
          $this->dropTable('contrato');
          return false;
       }
   }

1 answer

0


This problem happens when we don’t properly reference the path. In this case we only had to put the following reference in the configuration file

return [
        'class' => 'yii\db\Connection',
        'dsn'=>'sqlite:@app/db/portal.db',
        'charset' => 'utf8',
       ];

And the problem has been solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.