Rails 迁移在与 MSSQL [MicroSoft SQL SERVER] 一起使用时出现错误 - 找不到数据类型 Primary_key
我正在从事 Rails 3 项目,最初我使用 MySQL 作为 RDBMS。但后来我的客户要求我们使用MSSQL。花了半天时间,我能够使用这里的文章连接MSSQL服务器: http:// /oldwiki.rubyonrails.org/rails/pages/HowtoConnectToMicrosoftSQLServerFromRailsOnLinux
但经过所有的努力,当我尝试迁移时,出现以下错误:
Here rake db:migrate 出错
== CreateUsers: migrating ====================================================
-- create_table(:users)
rake aborted!
An error has occurred, all later migrations canceled:
37000 (2715) [unixODBC][FreeTDS][SQL Server]Column, parameter, or variable #1: Cannot find data type primary_key.
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
当我重新运行相同的命令时,我收到错误:
rake aborted!
S0001 (2714) [unixODBC][FreeTDS][SQL Server]There is already an object named 'schema_migrations' in the database.
- 这意味着至少连接正在工作!
以下是 rake db:schema:load 的错误,
-- create_table("banners", {:force=>true})
rake aborted!
37000 (2715) [unixODBC][FreeTDS][SQL Server]Column, parameter, or variable #1: Cannot find data type primary_key.
我在 google 上搜索了该错误,但找不到任何帮助,看来它不是一个流行的组合。
我目前正在以两种方式看待这个问题:
尝试通过使rails以MSSQL友好格式输出SQL来解决手头的问题。如果第一个失败,那么
作为解决方法,将原始 mysql 转储转换为 MSSQL 格式。
I am working on Rails 3 project where I initially used MySQL as RDBMS. But later my client requested that we should use MSSQL. After spending half a day, I am able to connect with the MSSQL server using the article here: http://oldwiki.rubyonrails.org/rails/pages/HowtoConnectToMicrosoftSQLServerFromRailsOnLinux
But after all the effort, when I tried to migrate, I got following error:
Here is error with rake db:migrate
== CreateUsers: migrating ====================================================
-- create_table(:users)
rake aborted!
An error has occurred, all later migrations canceled:
37000 (2715) [unixODBC][FreeTDS][SQL Server]Column, parameter, or variable #1: Cannot find data type primary_key.
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
When I re-run the same command, I get the error:
rake aborted!
S0001 (2714) [unixODBC][FreeTDS][SQL Server]There is already an object named 'schema_migrations' in the database.
- which means atleast connection is working!
Following is the error with rake db:schema:load
-- create_table("banners", {:force=>true})
rake aborted!
37000 (2715) [unixODBC][FreeTDS][SQL Server]Column, parameter, or variable #1: Cannot find data type primary_key.
I googled for the error but could not find any help, it seems its not a popular combination.
I am at present looking at this problem in two ways:
try to solve the problem in hand, by making rails output SQL in MSSQL friendly format. And if the first one fails then
as a workaround, convert the raw mysql dump to MSSQL format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于没有得到答案,我采用了接近上面#2 的解决方案。我使用 MSSQL 导入和导出向导通过 MySQL DSN 连接来一张一张地创建数据库表。我仍在寻找一种纯rails方式来做到这一点,因为每次我更改任何模型时,我都必须手动更新MSSQL数据库。
As I got no answers, I went with a solution close to #2 above. I created the database tables one by one by using MSSQL import and export wizard by connecting it through a MySQL DSN. I am still looking for a way to do this is pure rails way, because every time I change any models, I have to manually update the MSSQL database.