cleblanc87 / sqlserver-foreigner

Sqlserver support for foreigner
MIT License
5 stars 10 forks source link

Creating foreign keys on in development but not on deployment server #5

Open daveharris opened 9 years ago

daveharris commented 9 years ago

Hi,

I have a Rails 3.2.14 app which uses a SQLServer database. I'm using the usual combination of sqlserver-foreigner, foreigner and activerecord-sqlserver-adapter to make this all work.

I'm using foreigner methods in my migrations such as

def change
  change_table :readings do |t|
    t.foreign_key :reading_states
  end
end

After running rake db:migrate on my development machine, I get this added to the schema file

add_foreign_key "readings", "reading_states", name: "readings_reading_state_id_fk"

This is all good and I can see that the foreign key actually gets created in the database. Life is sweet.

However, if I deploy to my server, the foreign keys aren't created. Running a db:migrate has the following error:

$ bundle exec rake db:migrate
"Database adapter sqlserver not supported. Use:\nForeigner::Adapter.register 'sqlserver', 'path/to/adapter'"
  SQL (0.2ms)  USE [....]
   (0.2ms)  SELECT [schema_migrations].[version] FROM [schema_migrations]

I certainly don't get this error in development. Looking at the code in lib/sqlserver/foreigner.rb, I see that you register exactly the string is says isn't registered.

And looking in the db/schema.rb file on the server, all the add_foreign_key statements are missing. I've confirmed via EXEC sp_fkeys 'Readings' that no foreign keys exist on the server.

There are some very minor environmental differences between my development and the deployment. My development database is SQLServer Express 11.0.2100 whereas the deployment db is 10.50.2500.

So, do we need to upgrade the version in the deployment environment to be 11.x or is there something else I'm missing?

Thanks, Dave

kevinsheffield commented 7 years ago

+1