Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error during migration #102

Closed
s-ohnishi opened this issue Dec 13, 2022 · 3 comments
Closed

Fatal error during migration #102

s-ohnishi opened this issue Dec 13, 2022 · 3 comments

Comments

@s-ohnishi
Copy link
Contributor

I did the following for the migration.

vendor/bin/phalcon-migrations run --config=migrations.php

Then the following message is displayed.

Fatal Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY'

I don't understand it well, so I put
echo __CLASS__,'::',__FUNCTION__,':',__LINE__,PHP_EOL;
in many places and executed it, and the result is as follows.

Phalcon\Migrations\Console\Commands\Migration::run:102
Phalcon\Migrations\Migrations::run:387
Phalcon\Migrations\Mvc\Model\Migration::migrate:317
CompaniesMigration_100::afterCreateTable:115
Phalcon\Migrations\Mvc\Model\Migration::batchInsert:800
/srv/vendor/phalcon/migrations/src/Mvc/Model/Migration.php:903:
string(178) "INSERT INTO companies (id,name,telephone,address,city) VALUES ('1','Acme','31566564','Address','Hello'),('2','Acme Inc ','+44 564612345','Guildhall, PO Box 270, London','London');"
Phalcon\Migrations\Mvc\Model\Migration::migrate:324
CompaniesMigration_100::up:88
Phalcon\Migrations\Mvc\Model\Migration::batchInsert:800
/srv/vendor/phalcon/migrations/src/Mvc/Model/Migration.php:903:
string(178) "INSERT INTO companies (id,name,telephone,address,city) VALUES ('1','Acme','31566564','Address','Hello'),('2','Acme Inc ','+44 564612345','Guildhall, PO Box 270, London','London');"

It seems that afterCreateTable() and up() are called in succession in Migration::migrate.
(each calling batchInsert() )

Is this because these two are defined in companies.php?
Or is it a bug in phalcon/migrations?

@s-ohnishi
Copy link
Contributor Author

Both methods were also present in other .php files.
As a test, when I commented out each up() and executed it, the migration succeeded.

I'm not sure if this change is appropriate.

@aircodepl
Copy link
Contributor

Done in PR #106

Details: #106 (comment)

@s-ohnishi
Copy link
Contributor Author

thank you very much.
Good to know that I was not wrong in my thinking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants