# How to tell db:migrate to continue on exception

**URL:** <https://www.ruby-forum.com/t/how-to-tell-db-migrate-to-continue-on-exception/83435>\
**Category:** Rails\
**Created:** [January 26, 2007, 12:47am UTC](https://www.ruby-forum.com/t/how-to-tell-db-migrate-to-continue-on-exception/83435 "2007-01-26T00:47:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stan.baptista](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@stan.baptista](https://www.ruby-forum.com/u/stan.baptista)\
**Post date:** [January 26, 2007, 12:47am UTC](https://www.ruby-forum.com/t/how-to-tell-db-migrate-to-continue-on-exception/83435/1 "2007-01-26T00:47:37Z")

</div>

Is there a way to tell db:migrate to continue if it encounters an  
exception? Sometimes during developing, the migration files aren’t  
always exactly the way I want them (surprisingly;-).

For example:

001\_add\_table1.rb:

class AddTable1 \< ActiveRecord::Migration  
def self.up  
create\_table “table1”, :force =\> true do |t|  
t.column :string1, :string, :limit =\> 40, :null =\> false  
end  
end

def self.down  
drop\_table :table1  
end  
end

002\_add\_column.rb:

class AddColumn \< ActiveRecord::Migration  
def self.up  
add\_column :table1, :text1, :text, :null =\> false  
end

def self.down  
remove\_column :table1, :text1  
end  
end

Somewhere along the line I may end up deleting table ‘table1’ from the  
database inadvertently. So, if I run db:migrate, it’s quite likely to  
choke when applying version 2 (002\_add\_column.rb) or attempting a  
rollback to version 1.

But during development, I want it to keep going. Is there a way to do  
that?

Thanks,  
Stan

---

<div class="post-metadata">

**Author:** ![stan.baptista](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@stan.baptista](https://www.ruby-forum.com/u/stan.baptista)\
**Post date:** [January 26, 2007, 3:57pm UTC](https://www.ruby-forum.com/t/how-to-tell-db-migrate-to-continue-on-exception/83435/2 "2007-01-26T15:57:41Z")

</div>

On 1/25/07, stan.baptista [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> def self.up  
> 002\_add\_column.rb:
> 
> Somewhere along the line I may end up deleting table ‘table1’ from the  
> database inadvertently. So, if I run db:migrate, it’s quite likely to  
> choke when applying version 2 (002\_add\_column.rb) or attempting a  
> rollback to version 1.
> 
> But during development, I want it to keep going. Is there a way to do  
> that?
> 
> Thanks,  
> Stan

Usually deleting a table would be done as a migration too.

But, if you want migrations, and well, any ruby code, to continue on  
exceptions, look into the use of begin/rescue.

–  
Rick O.  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![stan.baptista](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@stan.baptista](https://www.ruby-forum.com/u/stan.baptista)\
**Post date:** [January 27, 2007, 10:02pm UTC](https://www.ruby-forum.com/t/how-to-tell-db-migrate-to-continue-on-exception/83435/3 "2007-01-27T22:02:30Z")

</div>

> But, if you want migrations, and well, any ruby code, to continue on  
> exceptions, look into the use of begin/rescue.

Got it. Thanks
