Migration gives an error
kussberg opened this issue · 22 comments
Hello,
just added your plugin via composer and i get an error when trying to do "php yii migrate":
Exception 'yii\base\InvalidConfigException' with message 'Object configuration must be an array containing a "class" element.'
in /vendor/yiisoft/yii2/BaseYii.php:353
Stack trace:
#0 /vendor/yiisoft/yii2/base/Module.php(583): yii\BaseYii::createObject(Array, Array)
#1 /vendor/yiisoft/yii2/base/Module.php(522): yii\base\Module->createController('')
#2 /vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate', Array)
#3 /vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('migrate', Array)
#4 /vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#5 /yii(20): yii\base\Application->run()
#6 {main}
Hi, could you give me more information about the error? What's your Yii, PHP versions?
Yii 2.0.15.1
PHP 7.1.8
It seems something wrong in settings of "migrate" component.
Please check the settings in your Yii config.
Should i look for something special?
I got it working after increasing the version:
"tigrov/yii2-country": "^1.1"
but now i have a new issue:
$ ./yii migrate --migrationPath=@vendor/tigrov/yii2-country/src/migrations
Yii Migration Tool (based on Yii v2.0.15.1)
Total 1 new migration to be applied:
m170405_112954_init
Apply the above migration? (yes|no) [no]:yes
*** applying m170405_112954_init
Error: Class m170405_112954_init does not exist
Can you try just
$ ./yii migrate
I tried this, here is what i get:
./yii migrate
Yii Migration Tool (based on Yii v2.0.15.1)
No new migrations found. Your system is up-to-date.
Please check your migrations table. Perhaps the migrations were applied with errors.
The migrations settings must be applied automatically as described in the bootstrap file https://github.com/Tigrov/yii2-country/blob/master/src/Bootstrap.php
It does not require to do anything for this, just run ./yii migrate
in console.
Hi both,
I had same issue than @ekussberg but my solution was to setup MigrateController into console/config/main.php:
'controllerMap' => [
'migrate' => [
'class' => 'yii\console\controllers\MigrateController'
],
],
@Tigrov I'm mostly coming back to Yii after few years on Magento, but I think it would be better if you make migrations in the old way, I know this feature is going to be used in the near future but right now it's pretty unstable and will prevent many others to use your nice module.
Now I can run ./yii migrate and my old migrations are not affected but I get another error:
*** applying tigrov\country\migrations\m170405_112954_init
> create table {{%country}} ... done (time: 0.232s)
> load into {{%country}} from /home/redbox/projects/projects-sgt/sgt2/yii2/vendor/tigrov/yii2-country/src/migrations/data/country.csv ...Exception: ob_flush(): failed to flush buffer. No buffer to flush (/home/redbox/projects/projects-sgt/sgt2/yii2/vendor/tigrov/yii2-country/src/migrations/m170405_112954_init.php:65)
Sounds like there is a ob_start() missing.
My setup:
"yiisoft/yii2": "2.0.15.1" // based on Advanced app
@matiashidalgo i have updated console PHP to point to different one with PHP Intl and now i get exactly same error as you described on top.
I fixed the issue by adding ob_start();
to the config/console.php
, but i think it should be in the beginning of the migration file. Now i get a new error:
> add primary key country_pkey on {{%country}} (code) ...Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'AD' for key 'PRIMARY'
@matiashidalgo fixed, ob_flush()
was removed.
@ekussberg perhaps the previous attempt to apply the migration was ended with errors and some tables were created and filled with data. Try to remove from DB follow tables country, division, division_translation, city, city_translation
and run the migration again.
I have installed again the latest version with composer. Deleted previous tables in the database. I am now getting following error:
*** applying tigrov\country\migrations\m170405_112954_init
> create table {{%country}} ... done (time: 0.030s)
> load into {{%country}} from /yii2/vendor/tigrov/yii2-country/src/migrations/data/country.csv ... filed: SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT LEVEL1 does not exist
The SQL being executed was: RELEASE SAVEPOINT LEVEL1
> trying batch insert ...
> insert into {{%country}} ... done (time: 0.012s)
> inserted 250 rows
> add primary key country_pkey on {{%country}} (code) ...Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'AD' for key 'PRIMARY'
The SQL being executed was: ALTER TABLE `country` ADD CONSTRAINT `country_pkey` PRIMARY KEY (`code`) (/yii2/vendor/yiisoft/yii2/db/Schema.php:664)
#0 /yii2/vendor/yiisoft/yii2/db/Command.php(1263): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE `co...')
#1 /yii2/vendor/yiisoft/yii2/db/Command.php(1075): yii\db\Command->internalExecute('ALTER TABLE `co...')
#2 /yii2/vendor/yiisoft/yii2/db/Migration.php(437): yii\db\Command->execute()
#3 /yii2/vendor/tigrov/yii2-country/src/migrations/m170405_112954_init.php(29): yii\db\Migration->addPrimaryKey('country_pkey', '{{%country}}', Array)
#4 /yii2/vendor/yiisoft/yii2/db/Migration.php(114): tigrov\country\migrations\m170405_112954_init->safeUp()
#5 /yii2/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(725): yii\db\Migration->up()
#6 /yii2/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(199): yii\console\controllers\BaseMigrateController->migrateUp('tigrov\\country\\...')
#7 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#8 /yii2/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /yii2/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#10 /yii2/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('', Array)
#11 /yii2/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('', Array)
#12 /yii2/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate', Array)
#13 /yii2/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('migrate', Array)
#14 /yii2/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#15 /yii2/yii(25): yii\base\Application->run()
#16 {main}
Yes, seems so. What SQL server and version do you use?
Fixed, try it now.
@Tigrov thanks, now it work for Country and Division. But now i get following error message:
Apply the above migrations? (yes|no) [no]:y
*** applying tigrov\country\migrations\m170405_112954_init
> create table {{%country}} ... done (time: 0.018s)
> load into {{%country}} from /yii/vendor/tigrov/yii2-country/src/migrations/data/country.csv ... done (time: 0.003s)
> add primary key country_pkey on {{%country}} (code) ... done (time: 0.049s)
> create table {{%division}} ... done (time: 0.016s)
> load into {{%division}} from /yii/vendor/tigrov/yii2-country/src/migrations/data/division.csv ... filed: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'geoname_id' at row 11
The SQL being executed was: LOAD DATA INFILE '/yii/vendor/tigrov/yii2-country/src/migrations/data/division.csv' INTO TABLE `division` FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '"'
> trying batch insert ...
> insert into {{%division}} ... done (time: 0.141s)
> inserted 3523 rows
> add primary key division_pkey on {{%division}} (country_code,division_code) ... done (time: 0.061s)
> create table {{%division_translation}} ... done (time: 0.023s)
> load into {{%division_translation}} from /yii/vendor/tigrov/yii2-country/src/migrations/data/division_translation.csv ... filed: SQLSTATE[HY000]: General error: 1300 Invalid utf8 character string: ''
The SQL being executed was: LOAD DATA INFILE '/yii/vendor/tigrov/yii2-country/src/migrations/data/division_translation.csv' INTO TABLE `division_translation` FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '"'
> trying batch insert ...
> insert into {{%division_translation}} ...Exception: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x90\x8D\x85\xF0\x90...' for column 'value' at row 3022
The SQL being executed was: INSERT INTO `division_translation`
...
...
...
#0 /yiivendor/yiisoft/yii2/db/Command.php(1263): yii\db\Schema->convertException(Object(PDOException), 'INSERT INTO `di...')
#1 /yii/vendor/yiisoft/yii2/db/Command.php(1075): yii\db\Command->internalExecute('INSERT INTO `di...')
#2 /yii/vendor/yiisoft/yii2/db/Migration.php(246): yii\db\Command->execute()
#3 /yii/vendor/tigrov/yii2-country/src/migrations/m170405_112954_init.php(100): yii\db\Migration->batchInsert('{{%division_tra...', Array, Array)
#4 /yii/vendor/tigrov/yii2-country/src/migrations/m170405_112954_init.php(36): tigrov\country\migrations\m170405_112954_init->loadFromCsv('{{%division_tra...', Array, '/yii/..')
#5 /yii/vendor/yiisoft/yii2/db/Migration.php(114): tigrov\country\migrations\m170405_112954_init->safeUp()
#6 /yii/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(725): yii\db\Migration->up()
#7 /yiii/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(199): yii\console\controllers\BaseMigrateController->migrateUp('tigrov\\country\\...')
#8 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
I am using MAMP PRO:
Server connection: SSL is not being used Documentation
Server version: 5.7.21 - MySQL Community Server (GPL)
Protocol version: 10
User: root@localhost
Server charset: UTF-8 Unicode (utf8)
It works fine on MySQL 5.5 but gives the error on MySQL 5.7
Now the error is fixed by using utf8mb4
instead of utf8
.
@Tigrov hah, looks good now! Just got some memory issue, will try to increase the limit to 512M:
PHP Fatal Error 'yii\base\ErrorException' with message 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 3478960 bytes)'
in /Users/edgarkussberg/PhpstormProjects/fursa/vendor/yiisoft/yii2/db/QueryBuilder.php:491
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
BTW i see also 2 different errors in the log:
> create table {{%division}} ... done (time: 0.017s)
> load into {{%division}} from /yii/vendor/tigrov/yii2-country/src/migrations/data/division.csv ... filed: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'geoname_id' at row 11
The SQL being executed was: LOAD DATA INFILE '/yii/vendor/tigrov/yii2-country/src/migrations/data/division.csv' INTO TABLE `division` FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '"'
> trying batch insert ...
> insert into {{%division}} ... done (time: 0.139s)
> inserted 3523 rows
> add primary key division_pkey on {{%division}} (country_code,division_code) ... done (time: 0.061s)
> create table {{%division_translation}} ... done (time: 0.054s)
> load into {{%division_translation}} from /yii/vendor/tigrov/yii2-country/src/migrations/data/division_translation.csv ... filed: SQLSTATE[HY000]: General error: 1300 Invalid utf8 character string: ''
The SQL being executed was: LOAD DATA INFILE '/yii/vendor/tigrov/yii2-country/src/migrations/data/division_translation.csv' INTO TABLE `division_translation` FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '"'
> trying batch insert ...
Try now but I'm not sure about the second error, it needs more info.
With memory limit 521 all went well 👌🏽