# ActiveRecord::Base.transaction MySQL Lock Errors

**URL:** <https://www.ruby-forum.com/t/activerecord-base-transaction-mysql-lock-errors/185752>\
**Category:** Rails\
**Created:** [March 25, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/activerecord-base-transaction-mysql-lock-errors/185752 "2010-03-25T16:44:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pablolemonski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pablolemonski](https://www.ruby-forum.com/u/pablolemonski)\
**Post date:** [March 25, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/activerecord-base-transaction-mysql-lock-errors/185752/1 "2010-03-25T16:44:01Z")

</div>

Hi there,

is there any known issues when using ActiveRecord::Base.transaction with  
models who tables have constraints applied?

I have two models:  
one (is associated with model two)  
two (has MySQL foreign key and unique key constraints)

I’m doing something like this:

ActiveRecord::Base.transaction  
one.create  
two.create(reference to one)

one.create  
two.create(reference to one)  
end

… which leads to something hanging and the transaction failing with  
MySQL table lock errors. What’s strange is that all works if I wrap each  
pair of creates within a Base.transaction of their own. Any pointers on  
the cause?

Thanks in advance!
