【发布时间】:2014-10-13 18:47:46
【问题描述】:
我尝试使用以下唯一约束创建下表。我收到以下代码的相同 MySQL 错误,以及我的研究建议应该有效的三个类似变体。
(defn create-prices-table [db]
(db-do-commands db (create-table-ddl :prices
[:priceid :integer "PRIMARY KEY" "AUTO_INCREMENT"]
[:productid :integer "references products (productid)"]
[:date "date"]
[:price "decimal(7,2)"]
:table-spec "UNIQUE KEY `uc_price` (`productid`, `date`)")))
其他尝试...
;; :table-spec "UNIQUE `uc_price` (`productid`, `date`)"
;; :table-spec "constraint uc_price unique (productid, date)"
;; :table-spec "constraint `uc_price` unique (`productid`, `date`)"
我在尝试执行时收到的消息...
CompilerException java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNIQUE KEY `uc_price` (`productid`, `date`)' at line 1, compiling:(schema_test.clj:38:41)
我正在使用 clojure.java.jdbc 库的 0.3.5 版。
编辑
create-string-ddl 返回
"CREATE TABLE prices (priceid integer PRIMARY KEY AUTO_INCREMENT, productid integer references products (productid), date date, price decimal(7,2)) UNIQUE KEY `uc_price` (`productid`, `date`)"
【问题讨论】:
-
你从
create-table-ddl函数得到什么字符串?