迁移时出现以下错误
我正在开发 Rails 2 项目,在运行 rake 任务时遇到以下错误。有人可以帮我看看可能是什么原因造成的吗?
[root@localhost webapp]# rake db:migrate
(in /root/public/webapp)
== CreateWhereKeywords: migrating ============================================
-- create_table(:where_keywords)
NOTICE: CREATE TABLE will create implicit sequence "where_keywords_id_seq" for serial column "where_keywords.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "where_keywords_pkey" for table "where_keywords"
-> 0.0838s
-- execute("alter table where_keywords add constraint where_keyword foreign key (where_location_id) references \n where_locations(id) on delete cascade")
rake aborted!
An error has occurred, this and all later migrations canceled:
PGError: ERROR: foreign key constraint "where_keyword" cannot be implemented
DETAIL: Key columns "where_location_id" and "id" are of incompatible types: character varying and integer.
: alter table where_keywords add constraint where_keyword foreign key (where_location_id) references
where_locations(id) on delete cascade
I am working on rails 2 project and am getting the following error while running rake tasks. Can someone help me out as what may be causing this.
[root@localhost webapp]# rake db:migrate
(in /root/public/webapp)
== CreateWhereKeywords: migrating ============================================
-- create_table(:where_keywords)
NOTICE: CREATE TABLE will create implicit sequence "where_keywords_id_seq" for serial column "where_keywords.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "where_keywords_pkey" for table "where_keywords"
-> 0.0838s
-- execute("alter table where_keywords add constraint where_keyword foreign key (where_location_id) references \n where_locations(id) on delete cascade")
rake aborted!
An error has occurred, this and all later migrations canceled:
PGError: ERROR: foreign key constraint "where_keyword" cannot be implemented
DETAIL: Key columns "where_location_id" and "id" are of incompatible types: character varying and integer.
: alter table where_keywords add constraint where_keyword foreign key (where_location_id) references
where_locations(id) on delete cascade
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误信息相当清楚:
当需要将
where_keywords.where_location_id
列创建为varchar
时,您将其创建为varchar
类型。integer
,以便它可以引用FK中的where_locations.id
。您的迁移有这样的内容:应该更像这样:
The error message is fairly clear:
You're creating the
where_keywords.where_location_id
column as avarchar
when it needs to be aninteger
so that it can refer towhere_locations.id
in the FK. Your migration has something like this:that should be more like this: