Comments (4)
Hello,
I know this is a bit old, but as the PR has not been merged yet, I feel like I need to tell my experience with this issue.
Using pomier's solution, seemed to work at first, but when trying to run Lhm.cleanup(true)
lot's of Foreign Key references errors were raised.
Looking a little further, it seemed that referenced tables had not been modified correctly.
The only thing that has worked for me is to remove foreign keys explicitly, run the Lhm migration and add foreign keys again inside the change_table body.
remove_foreign_key "fk_example", "users"
Lhm.change_table :fk_example do |m|
t.ddl "ALTER TABLE %s ADD CONSTRAINT `fk_rails_#{SecureRandom.hex(5)}` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);" % t.name
end
from lhm.
Also, migrating a table with outbound foreign key constraints fails on the temporary table creation step, because the new table tries to reuse the constraint name (errno: 121):
CREATE TABLE `fk_example` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_id` int(11) NOT NULL,
CONSTRAINT `fk_example_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and
Lhm.change_table :fk_example do |m|
# Nothing required, the create fails
end
Produce the following error:
[…]gems/mysql2-0.2.18/lib/active_record/connection_adapters/mysql2_adapter.rb:265:in `query': Mysql2::Error: Can't create table 'change_devel.lhmn_fk_example' (errno: 121): CREATE TABLE `lhmn_fk_example` ( (ActiveRecord::StatementInvalid)
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_example_ibfk_1` (`user_id`),
CONSTRAINT `fk_example_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 /* large hadron migration */
from […]gems/mysql2-0.2.18/lib/active_record/connection_adapters/mysql2_adapter.rb:265:in `block in execute'
from […]gems/activerecord-3.0.20/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `block in log'
from […]gems/activesupport-3.0.20/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
from […]gems/activerecord-3.0.20/lib/active_record/connection_adapters/abstract_adapter.rb:200:in `log'
from […]gems/mysql2-0.2.18/lib/active_record/connection_adapters/mysql2_adapter.rb:265:in `execute'
from […]gems/lhm-1.3.0/lib/lhm/connection.rb:135:in `execute'
from […]gems/lhm-1.3.0/lib/lhm/connection.rb:92:in `block in sql'
from […]gems/lhm-1.3.0/lib/lhm/connection.rb:91:in `each'
from […]gems/lhm-1.3.0/lib/lhm/connection.rb:91:in `sql'
from […]gems/lhm-1.3.0/lib/lhm/connection.rb:131:in `destination_create'
from […]gems/lhm-1.3.0/lib/lhm/migrator.rb:167:in `destination_create'
from […]gems/lhm-1.3.0/lib/lhm/migrator.rb:161:in `execute'
from […]gems/lhm-1.3.0/lib/lhm/command.rb:17:in `run'
from […]gems/lhm-1.3.0/lib/lhm/invoker.rb:37:in `run'
from […]gems/lhm-1.3.0/lib/lhm.rb:40:in `change_table'
(Note that the FK constraint on the new table is still named fk_example_ibfk_1
)
from lhm.
If you remove the foreign keys first, won't you get the issue where a cascade delete/update won't happen when the migration is running. Adding foreign key back later in LHM may cause reference error since the it cannot find the desired key to mapped to?
from lhm.
It seems like LHM should account for foreign keys, no? We got bitten by its lack of support in our dev environment. Luckily it didn't make it to prod...
from lhm.
Related Issues (20)
- Feature request: Support tables with gaps in the primary key column 'id' HOT 1
- lock_wait_timeout is readonly in older versions of SQL
- Any release coming that includes the slave_lag throttler? HOT 6
- Calculate Stride Size dynamically to avoid DeadLocks HOT 2
- How well does LHM play with Galera clusters? HOT 1
- Feature Request: Verification Step HOT 2
- Forgotten line HOT 2
- Completion percentage is wrong when IDs don't start at 1 HOT 2
- Undefined method 'rename_table' for Lhm
- Replication problems when running LHM
- Does LHM rebuild external constraints?
- table_exists deprecation warning
- LHM doesn't copy data when only 1 row and ID isn't 1 HOT 3
- Flag the repo as unmaintained? HOT 4
- Is there a way to get the no of records that were updated?
- p
- During LHM migration, Table is getting locked for bigger table and all our connections are holding up HOT 1
- Mysql 8 no display attribute on fields HOT 1
- Lhm locking table during column length change
- Archive the repo and redirect potential users to Shopify/lhm
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 lhm.