NutzCN Logo
问答 关于Daos.createTablesInPackage
发布于 3153天前 作者 qq_cd48ca64 2458 次浏览 复制 上一个帖子 下一个帖子
标签:

自动建表的时候 外建怎么创建
@Column
@ColDefine(type=ColType.VARCHAR,width=32)
private String userInfo_id;
@One(target = UserInfo.class, field = "userInfo_id")
public UserInfo userInfo;
这样建立不了外建关系
然后 如果有字段是唯一 唯一索引怎么建立
比如mail是唯一的 怎么能建立唯一索引

7 回复
  1. nutz.dao建的表均不会包含外键, nutz关联关系也不需要外键,也不理会外键.
  2. 在类上加注解
@TableIndex({@Index(name="i_mail", fields={"mail"}, unique=true)})

@wendal 但是现在有问题 如果我不建 他要给我删除。。。这是为什么
ALTER TABLE tb_userExpand DROP INDEX FK_tb_userExpand_tb_userInfo
启动的时候 会这样

严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: org.nutz.dao.DaoException: !Nutz SQL Error: 'ALTER TABLE tb_userExpand DROP INDEX FK_tb_userExpand_tb_userInfo'
PreparedStatement:
'ALTER TABLE tb_userExpand DROP INDEX FK_tb_userExpand_tb_userInfo'
CaseMessage=Cannot drop index 'FK_tb_userExpand_tb_userInfo': needed in a foreign key constraint
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
at org.nutz.lang.Mirror.born(Mirror.java:988)
at org.nutz.lang.Lang.wrapThrow(Lang.java:165)
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:134)
at org.nutz.mvc.ActionHandler.(ActionHandler.java:19)
at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4854)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5546)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.nutz.dao.DaoException: !Nutz SQL Error: 'ALTER TABLE tb_userExpand DROP INDEX FK_tb_userExpand_tb_userInfo'
PreparedStatement:
'ALTER TABLE tb_userExpand DROP INDEX FK_tb_userExpand_tb_userInfo'
CaseMessage=Cannot drop index 'FK_tb_userExpand_tb_userInfo': needed in a foreign key constraint
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:96)
at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:164)
at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:316)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:59)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:239)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:271)
at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:235)
at org.nutz.dao.util.Daos.migration(Daos.java:823)
at org.nutz.dao.util.Daos.migration(Daos.java:984)
at org.nutz.dao.util.Daos.migration(Daos.java:990)
at com.mxlvniao.userCenter.MainSetup.init(MainSetup.java:25)
at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:276)
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:120)
... 15 more
Caused by: java.sql.SQLException: Cannot drop index 'FK_tb_userExpand_tb_userInfo': needed in a foreign key constraint
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2505)
at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:840)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:740)
at com.alibaba.druid.pool.DruidPooledStatement.execute(DruidPooledStatement.java:421)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:321)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:52)
... 27 more

@wendal
Daos.migration(dao, "com.mxlvniao.entity.dao", true, false);
是这个

Daos.migration(dao, "com.mxlvniao.entity.dao", true, false, false);

@wendal 这样是不是索引我要完全自己来了?NUTZ就不会给我建了

Daos.createInPackage 是建表
Daos.migration 是对现有表进行修改

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