Comments (11)
As far as I'm concerned, I tried your code and had the same problem.
Out of curiosity, I executed the content of the up()
method in the app just at the end of the bootstrap.php file and it worked well.
So I dug further and I was able to make the migration work by passing the atomic
option of the save()
method to false
:
$table->save($entity, ['atomic' => false]);
This turns transaction off and avoid the exception to be raised, so it should work (I tested this on Cake 3.0.5).
As for why it is working when executing while migrating and not while executing the app itself, I have no idea. I'll try to investigate this but it might take some times since I don't really that part of the framework.
from migrations.
Apparently, Phinx starts a transaction by itself when migrating (see source).
Maybe that's what causing a problem here.
I'll take a deeper look when I get the chance. Maybe there is something that can be done to prevent this. But I'm sceptical since it works well with MySQL...
Meanwhile, the atomic
trick from my previous comment should work.
from migrations.
I think I figured it out.
After some poking around, I found out that phinx starts transactions with raw SQL statement (like BEGIN
or START TRANSACTION
).
However, it does not use the PDO::beginTransaction()
method which is causing the problem here I think.
If I change this method to
public function beginTransaction()
{
$this->execute('BEGIN');
$this->getConnection()->beginTransaction();
}
Otherwise, it seems to create some kind of conflicts.
I think the problem is within phinx and nothing can really be done in this plugin (we could maybe try and build our own adapters but that is not really viable in the long term in my opinion).
from migrations.
So make a pr for it in phinx?
from migrations.
@josegonzalez That is the plan. I just have to do extensive testing beforehand (and find time to do it).
from migrations.
Hi HavokInspiration,
I have try to use
$table->save($entity, ['atomic' => false]);
So far, its working now. I hope i can get the latest fix updated on newest release.
Thanks for all.
from migrations.
@dremi I started working on a fix for phinx yesterday night. I still need to do some tests.
Hopefully I'll be able to submit it tonight.
Glad to see the workaround is working for you.
from migrations.
Hi HavokInspiration,
Thanks for your update.
from migrations.
I gave this another round and I think there is nothing to actually fix.
Here's what is really going on :
1. Migration starts
2. Phinx starts a transaction
3. CakePHP ORM starts saving the given rows.
By default, at the end of a save, it commits the transaction created by Phinx
4. Phinx commits the transaction... but can not since it was already commited
And the problem is the other way around if the code base from phinx is left as is.
I have the same problem if phinx deals with transaction with PDO
methods rather than with raw queries with MySQL this time. Except that data is saved in the database and the migration failed right after, but the data is still there)
So I'm back to square one.
The only real way to have something working in all cases would be to disable transactions on Cake when running in Migrations.
This way, Phinx deals with commiting and rolling back transactions based on what's going on.
Is there a way to do it other than passing atomic
to false
? Have something more "global".
from migrations.
I can take a look at this @HavokInspiration
from migrations.
Closing as there is a pull request now.
from migrations.
Related Issues (20)
- Schema not quoted on Postgres HOT 2
- 4.x Migrations without Phinx HOT 11
- migration_diff warning `Undefined array key "precision"` HOT 2
- migrations and Phinx causes error with migrations due to INT casting on migration version HOT 1
- Using newQuery() is deprecated. Instead, use `insertQuery()`, `deleteQuery()`, `selectQuery()` or `updateQuery()`
- Baking fields HOT 2
- Migrate database snapshot HOT 1
- migration_diff generates incorrect code for decimal column definition change HOT 2
- Migration issues in Cake5 HOT 4
- blob column seems broken HOT 3
- Adding SET_NULL foreign keys fails HOT 6
- How to migrate migration files? HOT 6
- Baked migrations of bool should be tinyint(1) signed HOT 1
- Bake migration snapshot should not allow reserved words HOT 2
- RFC: [no-phinx] Show warning if table instance has actions attached which haven't been executed HOT 2
- RFC: [no-phinx] Check if given plugin actually exists before executing command HOT 1
- Contain migration name in error if pending actions are still present HOT 2
- use varchar instead of string? HOT 1
- rollback HOT 3
- bake migration_diff has issues with signed/unsigned primary keys and foreign keys. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from migrations.