【问题标题】:Attempted to drop columns containing foreign keys and received error message尝试删除包含外键的列并收到错误消息
【发布时间】:2011-10-29 19:44:32
【问题描述】:

我正在使用 phpMyAdmin 版本 3.3.10.3 来管理我的数据库。

我正在使用 InnoDB 和外键约束。

我试图从一个表中删除几列。这些列是引用其他表的外键。

ALTER TABLE `product`
  DROP `c_status_id`,
  DROP `o_certification_id`,
  DROP `g_free_certification_id`,
  DROP `gm_certification_id`,
  DROP `n_certification_id`;

在尝试查询时,我收到以下错误消息。

#1025 - Error on rename of ' /#sql-ea2_38d9f' to ' /product' (errno: 150

【问题讨论】:

  • 在错误中也是如此:SQLSTATE[HY000]: General error: 1025 (errno: 150) - 不是很具有描述性或易于谷歌搜索。我在这里发布了更多错误文本:wp.me/p3XdjT-11

标签: mysql phpmyadmin foreign-keys sql-drop


【解决方案1】:

您必须先删除外键关系,然后才能删除关系中引用的列。

ALTER TABLE 'TABLE_NAME' DROP FOREIGN KEY 'NAME_OF_FOREIGN_KEY'

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

【讨论】:

    猜你喜欢
    • 2018-03-20
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 1970-01-01
    相关资源
    最近更新 更多