Closed chibuzoro closed 4 years ago
In your case, add queries SET FOREIGN_KEY_CHECKS=?
before and after morph()
Example:
public function morph()
{
$this->getConnection()->execute('SET FOREIGN_KEY_CHECKS=0;');
$this->morphTable('accessToken', [...]);
$this->getConnection()->execute('SET FOREIGN_KEY_CHECKS=1;');
}
Closing in favour of #11
Expected and Actual Behavior
I dumped my SQL to the database (Postgres 9.4) and used devtools to generate ts-based migration files stored in db afterwards. All went well. However, after dropping the database and creating afresh, then attempting to run the same migrations generated by devtools (just simulating a fresh deployment), the migration fails with an error :
ERROR: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "public.client" does not exist"
I observed, the migrations may have been generated in a random order and so in an attempt to run on a fresh environment, the foreign table referenced may not have been created. Thus leading to errors.
References to similar issue:
Expected behaviour: Generate migration files from db with reference to defined foreign relationships, ensuring referenced tables get created first in the hierarchy.
Files listed in the order they were generated by phalcon devtools
Details
System info and versions (if possible): (
phalcon info
) Environment: OS: Linux edcef3d10fee 4.9.93-linuxkit-aufs phalcon/phalcon-devtools#1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 PHP Version: 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 PHP SAPI: cli PHP Bin: /usr/bin/php7.2 PHP Extension Dir: /usr/lib/php/20170718 PHP Bin Dir: /usr/bin Loaded PHP config: /etc/php/7.2/cli/php.ini Versions: Phalcon DevTools Version: 3.4.0 Phalcon Version: 3.4.0 AdminLTE Version: 2.3.6Phalcon Framework version: (
php --ri phalcon
) phalconWeb framework delivered as a C-extension for PHP phalcon => enabled Author => Phalcon Team and contributors Version => 3.4.0 Build Date => Jun 6 2018 04:54:09 Powered by Zephir => Version 0.10.10-d1b4cc68d9
Directive => Local Value => Master Value phalcon.db.escape_identifiers => On => On phalcon.db.force_casting => Off => Off phalcon.orm.events => On => On phalcon.orm.virtual_foreign_keys => On => On phalcon.orm.column_renaming => On => On phalcon.orm.not_null_validations => On => On phalcon.orm.exception_on_failed_save => Off => Off phalcon.orm.enable_literals => On => On phalcon.orm.late_state_binding => Off => Off phalcon.orm.enable_implicit_joins => On => On phalcon.orm.cast_on_hydrate => Off => Off phalcon.orm.ignore_unknown_columns => Off => Off phalcon.orm.update_snapshot_on_save => On => On phalcon.orm.disable_assign_setters => Off => Off
php -v
)PHP 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun 22 2018 08:44:50) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Xdebug v2.7.0alpha1, Copyright (c) 2002-2018, by Derick Rethans with Zend OPcache v7.2.7-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies