# Conditional migrations based on databased used

**URL:** <https://www.ruby-forum.com/t/conditional-migrations-based-on-databased-used/105595>\
**Category:** Rails\
**Created:** [May 31, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/conditional-migrations-based-on-databased-used/105595 "2007-05-31T16:02:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgrosjean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@jgrosjean](https://www.ruby-forum.com/u/jgrosjean)\
**Post date:** [May 31, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/conditional-migrations-based-on-databased-used/105595/1 "2007-05-31T16:02:13Z")

</div>

I’m trying to add a migration with foreign keys like this:

execute ‘ALTER TABLE projects ADD CONSTRAINT fk\_project\_user FOREIGN KEY  
( user\_id ) REFERENCES users ( id )’

the problem is that for development i’m using sqlite and I don’t think  
that support foreign keys, at least the migration is giving me this  
error:

– execute("ALTER TABLE projects ADD CONSTRAINT fk\_projects\_user FOREIGN  
KEY ( user\_id ) REFERENCES users( id ) ")  
rake aborted!  
SQLite3::SQLException: near “ADD”: syntax error: ALTER TABLE projects  
ADD CONSTRAINT fk\_projects\_users FOREIGN KEY ( user\_id ) REFERENCES  
users( id )

So my question is how can I test to see what database the migration is  
working on so that I can do the execute on mysql (production), but not  
on sqlite (development)?

And of course if what I’m trying to do doesn’t really make sense, or  
there’s a better way, please let me know.

Thanks,  
Jesse

---

<div class="post-metadata">

**Author:** ![jgrosjean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@jgrosjean](https://www.ruby-forum.com/u/jgrosjean)\
**Post date:** [May 31, 2007, 4:08pm UTC](https://www.ruby-forum.com/t/conditional-migrations-based-on-databased-used/105595/2 "2007-05-31T16:08:22Z")

</div>

Can’t tell you anything about the error, but my question is. Why  
aren’t you you developing on mysql? in my opinion it makes no sense to  
develop on sqlite and deploy on mysql. install mysql on your box and  
develop on the same database.

---

<div class="post-metadata">

**Author:** ![jgrosjean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@jgrosjean](https://www.ruby-forum.com/u/jgrosjean)\
**Post date:** [May 31, 2007, 4:36pm UTC](https://www.ruby-forum.com/t/conditional-migrations-based-on-databased-used/105595/3 "2007-05-31T16:36:57Z")

</div>

I’d been using sqlite because it was a bit faster for development and  
running tests. But at this point in development your are probably right,  
I’ll move everything to mysql. Thanks.
