Forum: Ruby on Rails conditional migrations based on databased used

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jesse G. (Guest)
on 2007-05-31 18:02
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
dweinand (Guest)
on 2007-05-31 18:08
(Received via mailing list)
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.
Jesse G. (Guest)
on 2007-05-31 18:36
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.
This topic is locked and can not be replied to.