NutzCN Logo
问答 postgresql 索引检查错误
发布于 432天前 作者 忧郁深蓝 1671 次浏览 复制 上一个帖子 下一个帖子
标签:

nutzboot 2.6
启动的时候修改表结构,有去检查索引变动,会生成下面的SQL语句

ALTER TABLE 表名 DROP INDEX 索引名

会抛出异常

org.nutz.ioc.IocException: IocBean[mainLauncher] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
	at org.nutz.boot.NbApp.execute(NbApp.java:214)
	at org.nutz.boot.NbApp.run(NbApp.java:182)
Caused by: org.nutz.dao.DaoException: !Nutz SQL Error: 'ALTER TABLE sys_user DROP INDEX sys_user_pkey'
PreparedStatement: 
'ALTER TABLE sys_user DROP INDEX sys_user_pkey'
CaseMessage=错误: 语法错误 在 "sys_user_pkey" 或附近的
  位置:33
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:110)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:65)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:63)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:138)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:164)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:110)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:94)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:80)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:78)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:242)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:254)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:238)
	at org.nutz.dao.util.Daos.migration(Daos.java:844)
	at org.nutz.dao.util.Daos.migration(Daos.java:765)
	at org.nutz.dao.util.Daos.migration(Daos.java:1002)
	at org.nutz.dao.util.Daos.migration(Daos.java:1020)
	at com.silly.MainLauncher.init(MainLauncher.java:68)
	at org.nutz.lang.reflect.f99c17eaa0010e3cf6b797e734b7023c$FM$init$58c1c56348535eec0d83a79af41ef16d.invoke(MainLauncher.java)
	at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:181)
	at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:89)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:141)
	... 5 common frames omitted

我尝试复制出来语句在命令行执行,发现如果删除索引的话,可以用

DROP INDEX index_sys_user_mobile

执行;
又跟踪了下代码,发现在org.nutz.dao.util.Daos 916行添加个判断,就可以正常执行了!

if (dao.meta().isSqlServer()) {
                delSqls.add(Sqls.createf("DROP INDEX %s.%s",
                                         getTableName(dao, en, t),
                                         indexName));
            } else {
                delSqls.add(Sqls.createf("ALTER TABLE %s DROP INDEX %s",
                                         getTableName(dao, en, t),
                                         indexName));
            }

当然,也可以使用

Daos.migration(dao, "包", true, true, false);

这个命令跳过索引检查

1 回复

一般接这些数据库(达梦、人大金仓、postgresql)都会跳过自动修改表结构、检查索引等功能

添加回复
请先登陆
回到顶部