Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails when attempting to load DB schema #723

Open
rhysforyou opened this issue Jan 28, 2020 · 4 comments
Open

Fails when attempting to load DB schema #723

rhysforyou opened this issue Jan 28, 2020 · 4 comments

Comments

@rhysforyou
Copy link

rhysforyou commented Jan 28, 2020

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.

@wpolicarpo
Copy link
Member

Hey, what version of Rails are you running?

@rhysforyou
Copy link
Author

The project exhibiting this issue is running Rails 5.2.3

@wpolicarpo
Copy link
Member

@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?

@wpolicarpo wpolicarpo self-assigned this May 16, 2020
@simonrentzke
Copy link

simonrentzke commented Jul 12, 2021

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!

@wpolicarpo wpolicarpo removed their assignment Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants