简体   繁体   English

Rails - SQLite3::SQLException:在“USING”附近:语法错误

[英]Rails - SQLite3::SQLException: near “USING”: syntax error

I've recently deployed my app to Heroku and in doing so I had to make some amends to a couple of columns in one of my tables.我最近将我的应用程序部署到 Heroku,这样做时我不得不对我的一个表中的几列进行一些修改。 Specifically, I did the following:具体来说,我做了以下事情:

class ChangeCancelColumnOrders < ActiveRecord::Migration
  def change
    change_column :orders, :cancel, 'boolean USING CAST(cancel AS boolean)'
  end
end

IE I added the 'boolean USING CAST(cancel AS boolean)' part because when trying to do a heroku run rake db:migrate it was giving this error: IE 我添加了'boolean USING CAST(cancel AS boolean)'部分,因为在尝试执行heroku run rake db:migrate它给出了这个错误:

PG::DatatypeMismatch: ERROR: column "cancel" cannot be cast automatically to type boolean

This has been fixed and everything works fine on Heroku.这已得到修复,并且在 Heroku 上一切正常。

Now the problem is that when I attempt to run rake db:migrate locally, I get the following error:现在的问题是,当我尝试在本地运行rake db:migrate ,出现以下错误:

SQLite3::SQLException: near "USING": syntax error:
CREATE TABLE "orders" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255), "address_1" varchar(255), "address_2" varchar(255), "city" varchar(255), "postal_code" varchar(255), "country_code" varchar(255), "shipped_date" date, "total_price" integer, "shipped" boolean DEFAULT 'f', "cancel" boolean USING CAST(cancel AS boolean) DEFAULT 'f', "cancel_date" date)

I can see that boolean USING CAST(cancel AS boolean) has been added to the cancel column but I don't know how to go about resolving this?我可以看到boolean USING CAST(cancel AS boolean)已添加到cancel列,但我不知道如何解决这个问题?

If I got that correctly, you are developing with SQLite , but deploying to Postgres on Heroku.如果我理解正确,那么您正在使用SQLite进行开发,但是在 Heroku 上部署到Postgres

This is the problem.就是问题所在。 The solution is to develop with Postgres locally as well.解决方案是在本地也使用 Postgres 进行开发。 Best with the same version.最好用同版本。 There are numerous differences in the SQL implementation and you will keep running into obstacles as soon as you use anything else than basic DML commands. SQL 实现中有许多不同之处,一旦使用基本 DML 命令以外的任何其他命令,您就会不断遇到障碍。

There is nothing equivalent in SQLite like this PostgreSQL DDL command:在 SQLite 中没有像这个 PostgreSQL DDL 命令这样的等价物:

ALTER TABLE orders ALTER cancel TYPE boolean USING CAST(cancel AS boolean);

The SQLite implementation of ALTER TABLE is very limited. ALTER TABLE的 SQLite 实现非常有限。 Per documentation:根据文档:

SQLite supports a limited subset of ALTER TABLE. SQLite 支持有限的 ALTER TABLE 子集。 The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. SQLite 中的 ALTER TABLE 命令允许用户重命名表或向现有表添加新列。

For all other changes to the table schema there is a recipe in the SQLite manual.对于表模式的所有其他更改, SQLite 手册中有一个配方。

Related answer:相关回答:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ruby on rails:多次插入SQLite3 :: SQLException:在“,”附近:语法错误: - ruby on rails: multiple insertion SQLite3::SQLException: near “,”: syntax error: SQLite3 :: SQLException:在“ CONSTRAINT”附近:语法错误 - SQLite3::SQLException: near “CONSTRAINT”: syntax error Rails 4 SQLite3 :: SQLException错误 - Rails 4 SQLite3::SQLException error 为什么ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:在“)附近:语法错误:INSERT INTO“ user_friendships”()VALUES() - Why ActiveRecord::StatementInvalid: SQLite3::SQLException: near “)”: syntax error: INSERT INTO “user_friendships” () VALUES () 如何修复SQLite3 :: SQLException:在“至”附近:语法错误:SELECT“”。* FROM“” WHERE“”。”” =? AND(到&lt;&#39;[Time.now]&#39;)LIMIT? OFFSET? - How to fix SQLite3::SQLException: near “to”: syntax error: SELECT “”.* FROM “” WHERE “”.“” = ? AND (to < '[Time.now]') LIMIT ? OFFSET? Rails SQLite3 :: SQLException - Rails SQLite3::SQLException Rails中的SQLite3错误SQLite3 :: SQLException:没有这样的列 - SQLite3 error in rails SQLite3::SQLException: no such column SQLite3 :: SQLException:在“&”附近:语法错误:SELECT“ pages”。* FROM“ pages” WHERE(menu_display = true &amp;&amp; is_published = true) - SQLite3::SQLException: near “&”: syntax error: SELECT “pages”.* FROM “pages” WHERE (menu_display=true && is_published=true) Rails 6 sqlite3中的更新/删除语法错误 - Update/Delete syntax error in rails 6 sqlite3 Rails关联:SQLite3 :: SQLException:没有这样的列 - Rails Associations: SQLite3::SQLException: no such column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM