We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Apply old phalcon migrations on v4.x

It seems that old migrations (Phalcon v3.4.x) are not being able to run on Phalcon v4.x . Is there a way to do that without changing a lot of code?

What I got when trying ot apply migrations:

[email protected]:/var/www/html/shop_products# app/common/library/vendor/bin/phalcon-migrations migration run --migrations=app/migrations/ --config=../../../../etc/shop/products.yml

Phalcon Migrations

Fatal error: Uncaught TypeError: Argument 3 passed to Phalcon\Db\Index::__construct() must be of the type string, null given in /var/www/html/shop_products/app/migrations/1.0.0/rate_images.php:80
Stack trace:
#0 /var/www/html/shop_products/app/migrations/1.0.0/rate_images.php(80): Phalcon\Db\Index->__construct('rate_images_pro...', Array, NULL)
#1 /var/www/html/shop_products/app/common/library/vendor/phalcon/migrations/src/Mvc/Model/Migration.php(514): RateImagesMigration_100->morph()
#2 /var/www/html/shop_products/app/common/library/vendor/phalcon/migrations/src/Migrations.php(360): Phalcon\Migrations\Mvc\Model\Migration::migrate('rate_images', Object(Phalcon\Migrations\Version\IncrementalItem), Object(Phalcon\Migrations\Version\IncrementalItem))
#3 /var/www/html/shop_products/app/common/library/vendor/phalcon/migrations/src/Console/Commands/Builtin/Migration.php(158): Phalcon\Migrations\Migrations::run(Array)
#4 /var/www/html/shop_products/app/common/library/vendor/phalcon/migrations/src/Console/Script.php(107): Phalcon in /var/www/html/shop_products/app/migrations/1.0.0/rate_images.php on line 80


7.0k
Accepted
answer
edited Jan '20

The problem was in type hinting for the new version of Phalcon 4.x Before, the constructor of Phalcon\Db\Index was accepting third argument as null, now it is strctly a string.

I updated my migrations to pass it as empty string instead of null.



10.1k

You can easily scan you codebase with rector. If you have docker running I got a container here: https://github.com/ruudboon/phalcon-docker-rector