rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
968 stars 558 forks source link

TinyTds::Error: Type T_FK is not a defined system type. #844

Open nPaul opened 3 years ago

nPaul commented 3 years ago

Rails version 6 multi database using

for example if run db:rollback got error:

--trace log



** Invoke db:rollback (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:rollback
== 20200810025414 AddDescriptionToOrders: reverting ===========================
-- remove_column(:orders, :description, :string)
   -> 0.0017s
== 20200810025414 AddDescriptionToOrders: reverted (0.0026s) ==================

** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke db:load_config 
** Execute db:schema:dump
rails aborted!
ActiveRecord::StatementInvalid: TinyTds::Error: Type T_FK is not a defined system type
```.

other databases is normal dumped after db:migration and db:rollback
this error got also if run
rails db:migrate:down:primary VERSION=123123123

i think sql adapter has bug on dumping command
nPaul commented 3 years ago

FREETDS version

tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v1.1.24
             freetds.conf directory: /usr/local/etc
     MS db-lib source compatibility: no
        Sybase binary compatibility: no
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 7.3
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: no
                            OpenSSL: yes
                             GnuTLS: no
                               MARS: yes
defaultzero commented 2 weeks ago

I'm having the exact issue. Were you able to solve this?

defaultzero commented 2 weeks ago

To be more helpful, this is caused by connecting to our ERP 2012 SQL Server DB. It has many different custom column types. SiteType, being among them. All which cause the error, TinyTds::Error: Type SiteType is not a defined system type.

It would be helpful to know how to pass custom system types to TinyTDS. Many of these are datatypes are glorified strings.

Is it possible to map, for instance, SiteType = String, somewhere, so that TinyTDS can handle?

aidanharan commented 2 weeks ago

There is an article about using custom data types in Rails with PostgreSQL https://pganalyze.com/blog/custom-postgres-data-types-ruby-rails

The same technique might work for the SQL Server adapter but I've never tried it myself.