activerecord-sqlserver-adapter
activerecord-sqlserver-adapter copied to clipboard
Fails when attempting to load DB schema
When running bin/rake db:schema:load
in a project using activerecord-sqlserver-adapter, the process mostly works, with all the tables, indices, and so on being created. However, it fails at the last second with the following error:
rake aborted!
TypeError: can't cast ActiveRecord::ConnectionAdapters::SQLServer::Type::Data
/Users/rpowell/Code/REDACTED/db/schema.rb:13:in `<main>'
-e:1:in `<main>'
Caused by:
TypeError: TypeError
/Users/rpowell/Code/REDACTED/db/schema.rb:13:in `<main>'
-e:1:in `<main>'
Tasks: TOP => db:schema:load
(See full trace by running task with --trace)
where line 13 of schema.rb
is the outermost call to Schema.define
:
ActiveRecord::Schema.define(version: 2019_11_22_023524) do
Currently I work around this by running db:migrate
every time I need to set up a database from scratch, but the Rails team advises against this for a variety of sensible reasons, and I'd prefer to be able to use the Rails-endorsed approach of loading the schema directly.
Hey, what version of Rails are you running?
The project exhibiting this issue is running Rails 5.2.3
@rhysforyou I am looking into this error now... are you working with multiple databases? Can you post your Gemfile
or maybe create a minimal application isolating the error?
Hi @wpolicarpo, I'm having the same problem, when using multiple databases with latest Rails 6.1.4, and SQL server adapter 6.1.0.0, and Postgres.
Here is a repo to reproduce the failure, with reproduction steps in the Readme: https://github.com/simonrentzke/rails-sqlserver-adapter-bug
It has something to do with how Rails handles the AR Internal Metadata table, the error stops occurring when I set use_metadata_table: false
in the database.yml.
Thanks!