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

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.phalcon.io/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?



13.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?



1.9k

cd phalcon_dev_tools git checkout 3.3.* git pull

try phalcon migration run alain =)



1.6k

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



1.6k
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.



1.6k

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);

} ...

}



1.9k
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 ?



1.6k

php -m | grep phalcon

Finded ?

Yes, found

phalcon



181
Accepted
answer

Try

sefl::$connection

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