I found some bug in sqlite-conf, I don't know, but it doesnt seems to work as it intended.
The thing I have the following db.php
file
return [
'class' => 'yii\db\Connection',
'dsn' => 'sqlite:somedb',
'charset' => 'utf8',
];
I can create and run migrations
use yii\db\Migration;
use yii\db\sqlite\Schema;
class m160222_083002_create_some_table extends Migration
{
public function up()
{
$this->createTable('some_table', [
'id' => Schema::TYPE_PK,
'name' => Schema::TYPE_STRING
]);
}
public function down()
{
$this->dropTable('some_table');
}
}
these are works fine, creates table etc.
$ ./yii migrate
Yii Migration Tool (based on Yii v2.0.7)
Total 1 new migration to be applied:
m160222_083002_create_some_table
Apply the above migration? (yes|no) [no]:y
*** applying m160222_083002_create_some_table
> create table some_table ... done (time: 0.109s)
*** applied m160222_083002_create_some_table (time: 0.170s)
1 migration was applied.
Migrated up successfully.
But then comes some magic. I can't use gii generators from my local server, e.g.
somelocal.loc/gii/model
when I enter table name like
some_table
Answer is
Table 'some_table' does not exist.
However running gii model generator from CLI runs perfect
$ ./yii gii/model --tableName=some_table --modelClass=someTable
Running 'Model Generator'...
The following files will be generated:
[new] models/someTable.php
Ready to generate the selected files? (yes|no) [yes]:y
Files were generated successfully!
Generating code using template "/var/www/sweethouse.loc/vendor/yiisoft/yii2-gii/generators/model/default"...
generated models/someTable.php
done!
it generates the following code
namespace app\models;
use Yii;
/**
* This is the model class for table "some_table".
*
* @property integer $id
* @property string $name
*/
class someTable extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'some_table';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
];
}
}
But if only
somelocal.loc/gii/model
didn't work, that wouldn't be pity, CLI generator is more friendly.
But the most important problem for me that mysite cant resolve tablenames, ActiveRecord doesn't see it, and crashes site with following error
Database Exception – yii\db\Exception
SQLSTATE[HY000]: General error: 1 no such table: some_table
Failed to prepare SQL: SELECT * FROM `some_table`
Error Info: Array
(
[0] => HY000
[1] => 1
[2] => no such table: some_table
)
↵
Caused by: PDOException
SQLSTATE[HY000]: General error: 1 no such table: some_table
in /var/www/mysite/vendor/yiisoft/yii2/db/Command.php at line 225
And controller action, where I want to access my table values
public function actionSome()
{
$some = someTable::find()->all();
return $this->render('some',[
'some' => $some
]);
}
The following error comes only with sqlite3 database