Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

an error while running a migration

Hi, everyone.

I have phalcon 3.3 and devtools 3.4.0

when I try to run a migration like so

phalcon migration run --version=1.0.1

where in the php code I use

self::$_connection->...

inside up() I get an error

Access to undeclared static property: VersionsMigration_101::$_connection

According to the following this should be working https://docs.phalconphp.com/en/3.3/db-migrations#writing-migrations

and I had it working. Not sure what happened.

I tried to dig into this and got another weird dilema,

I could not find class Phalcon\Mvc\Model\Migration anywhere in Phalcon source

I would expect a file migration.zep or something like that in here https://github.com/phalcon/cphalcon/tree/master/phalcon/mvc/model Tried even searching for "Migration" in any of the files. Nothing. What am I doing/thinking wrong?



8.8k

Did you change your developer tools version or anything? I remember i once had problems with it after I changed developer tools versions. It also generates a directory .phalcon . Did you include that aswell?



694

cd phalcon_dev_tools git checkout 3.3.* git pull

try phalcon migration run alain =)

Thanks. So I pulled and switched to branch 3.3.x. This did not seem to help though. :(

edited Jul '18

Did you change your developer tools version or anything? I remember i once had problems with it after I changed developer tools versions. It also generates a directory .phalcon . Did you include that aswell?

Okay, here is what happened to the best of my knowledge. I worked on this site on a local server (ubuntu 16.04 + apache on a local network). Everything was working, migrations including. then I had a break for a couple of weeks, When I came back to it Idecided to change db structure a bit, removed old migrations 1.0.0-5 (had quite a few of them by the time), removed the file in /.phalcon that stores migration versions, made changes to the database manually and ran "phalcon migration generate". to generate 1.0.0 again. Then I updated vendors/libs via composer. I have dev-tools installed that way too, and when I made a new 1.0.1 manually with the $_connection in the code and attempted to run the migration this is when I noticed the problem.

Here is the full print out

PHP Fatal error: Uncaught Error: Access to undeclared static property: VersionsMigration_101::$_connection in /www/sapi/app/migrations/1.0.1/versions.php:12

Stack trace:

0 /www/sapi/vendor/phalcon/devtools/scripts/Phalcon/Mvc/Model/Migration.php(488): VersionsMigration_101->up()

1 /www/sapi/vendor/phalcon/devtools/scripts/Phalcon/Migrations.php(297): Phalcon\Mvc\Model\Migration::migrate(Object(Phalcon\Version\IncrementalItem), Object(Phalcon\Version\IncrementalItem), 'versions')

2 /www/sapi/vendor/phalcon/devtools/scripts/Phalcon/Commands/Builtin/Migration.php(143): Phalcon\Migrations::run(Array)

3 /www/sapi/vendor/phalcon/devtools/scripts/Phalcon/Script.php(117): Phalcon\Commands\Builtin\Migration->run(Array)

4 /www/sapi/vendor/phalcon/devtools/scripts/Phalcon/Script.php(151): Phalcon\Script->dispatch(Object(Phalcon\Commands\Builtin\Migration))

5 /www/sapi/vendor/phalcon/devtools/phalcon.php(76): Phalcon\Scri in /www/sapi/app/migrations/1.0.1/versions.php on line 12

and here is simplified migration code with the self::$_connection line #12 that caused the error

<?php

use Phalcon\Mvc\Model\Migration;

class VersionsMigration_101 extends Migration {

private $table_name = 'versions';

public function up() {

self::$_connection->query('TRUNCATE TABLE ' . $this->table_name);

} ...

}



694
edited Jul '18

maybe phalcon.so not included in cli php ? execute in console :

php -m | grep phalcon 

Finded ? P.S how insert tag for formatting code here ?

php -m | grep phalcon

Finded ?

Yes, found

phalcon



176
Accepted
answer

Try

sefl::$connection

Phalcon\Mvc\Model\Migration located at PATH_TO_PHALCON_DEVTOOLS/scripts/Phalcon/Mvc/Model/Migration.php