SQLSTATE [HY000]: General error: 1 no such table: contract Failed to prepare SQL: SELECT * FROM 'contract'

0

I'm using yii2 for a small project, I'm using sqlite to persist the data. So that's where the problem is. Any table I create in sqlite yii2 does not recognize, nor by using the GII to create the models. Interesting is that it plugs into the bank properly. I created the table with a migration.

The 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',
    ];

Migration code:

<?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;
       }
   }
    
asked by anonymous 07.12.2018 / 19:14

1 answer

0

This problem happens when we do not reference the path properly. In this case it was only necessary to place 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.

    
13.12.2018 / 15:44