V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
rogwan
V2EX  ›  MySQL

MySQL 为什么不能删除( drop)索引( index)?

  •  
  •   rogwan · 2016-12-22 22:37:45 +08:00 · 4882 次点击
    这是一个创建于 2681 天前的主题,其中的信息可能已经有所发展或是发生改变。

    class Student(db.Model):

    tablename = 'students'
    id = db.Column(db.Integer, primary_key=True)
    student_name = db.Column(db.String(32), index=True)

    mysql> alter table students drop index student_name;

    提示错误: ERROR 1091 ( 42000 ): can't drop 'student_name'; check that column/key exists

    用 show index from students 看了,明明 student_name 有加索引啊,怎么去除 drop 不掉呢?(考虑到有会有很多名字重复,就不加索引了)

    2 条回复    2016-12-23 11:18:09 +08:00
    nomaka
        1
    nomaka  
       2016-12-22 22:53:13 +08:00   ❤️ 1
    show index from students 你要看 key name 是啥 你要删索引的名字 不是 字段的名字啊
    rogwan
        2
    rogwan  
    OP
       2016-12-23 11:18:09 +08:00
    @nomaka 那个是系统自动生成的 key_name 是 ix_students_student_name ,开始没敢删 -:)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1030 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:09 · PVG 06:09 · LAX 15:09 · JFK 18:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.