草庐IT

Price_Foreign

全部标签

MySQL 错误号 : 150 "Foreign key constraint is incorrectly formed"

有谁知道为什么我会收到以下错误消息?errno:150"Foreignkeyconstraintisincorrectlyformed"CREATETABLEmeter(`code`CHAR(5)NOTNULL,`type`VARCHAR(30)NOTNULL,descriptionVARCHAR(30)NULL,location_codeCHAR(3)NOTNULL,CONSTRAINTpri_meterPRIMARYKEY(`code`),CONSTRAINTfor_meterFOREIGNKEY(location_code)REFERENCESlocation(`code`));

mysql - 错误 1452 (23000) : Cannot add or update a child row: a foreign key constraint fails for existing tables

将外键分配给现有表列时出现以下错误:ERROR1452(23000):Cannotaddorupdateachildrow:aforeignkeyconstraintfails(c_x_parsing.#sql-787_1,CONSTRAINT#sql-787_1_ibfk_1FOREIGNKEY(nct_id)REFERENCEScdb(nct_id))下面是我的查询:ALTERTABLEc_intADDFOREIGNKEY(n_id)REFERENCEScdb(n_id);虽然我的父表是cdbcdb,子表是c_int。请给我建议解决方案,因为我已经尝试过以下命令:ALTERTABL

mysql - rails 引擎 : Namespacing foreign key references to other models in the same engine

我已经为名为TestAppTv的数据库设置了一个带有MySQL的命名空间Rails3.2.19引擎,它有2个模型:发布和评论。我希望Comments属于Posts,但我希望它具体引用TestAppTv::Post。我知道我可以通过指定class_name以及我的belongs_to/has_many调用来做到这一点。moduleTestAppTvclassComment现在,我的困惑在于数据库。test_app_tv_comments表中默认的foreign_key似乎是“post_id”。但是,在我看来,这并没有遵循与应用程序其余部分相同的命名空间思想。post_id是指test_a

php - Laravel 迁移 : Remove onDelete ('cascade' ) from existing foreign key

我创建了一个这样的迁移://...$table->foreign('a')->references('b')->on('c')->onDelete('cascade');//...我想在新迁移中删除onDelete('cascade')而不破坏任何东西。我该怎么做? 最佳答案 你可以尝试删除旧的外键并添加然后添加一个新的没有onDelete:$table->dropForeign(['a']);$table->foreign('a')->references('b')->on('c');

mysql - 错误 : Error 1215: Cannot add foreign key constraint

我收到错误:错误:错误1215:无法添加外键约束我阅读了其他类似主题和http://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html显然我无法解决这个问题。代码生成如下(该死的它应该可以完美运行):SET@OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS,UNIQUE_CHECKS=0;SET@OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,FOREIGN_KEY_CHECKS=0;SET@OLD_SQL_MODE=@@SQL_MODE,SQL_MODE

MySQL 查询 : find in which range quantity resides and then get the price of max quantity in the range

在构建查询方面需要帮助。我有quantity_price表,列出数量和相应的价格如下所示QuantityPrice----------------1--€175,352.5--€160,655--€149,1010--€143,85因此,最多1个数量的价格为175,35,最多2.5个数量的价格为160,65,依此类推。数量超过10个,价格会保持在143,85。现在,如果我的数量是1.5,那么查询应该返回价格160,65,这意味着找到数量所在的范围,然后获取该范围内最大数量的价格。 最佳答案 使用where语句查找所有大于1.5的行;

mysql - sails .js : Waterline foreign key association missing in MySQL

我在sails.js中使用水线ORM。我有一个用户模型和另一个与用户模型关联的硬币模型。//coins.jsattributes:{name:'string',//AssociationsuserId:{model:'user'}}为此模型生成的查询是CREATETABLE`coins`(`name`VARCHAR(255),`userId`INT,`id`INTUNSIGNEDNOTNULLAUTO_INCREMENTPRIMARYKEY,`createdAt`DATETIME,`updatedAt`DATETIME)查询应该包含userId的外键约束,但没有。有解决办法吗?

java - 无法添加或更新子行 : a foreign key constraint fails

有人知道我的代码有什么问题吗?我正在使用一个简单的INSERT语句(而不是常规的PreparedStatement,因为我正在尝试利用mySQL的AES_ENCRYPT/DECRYPT函数。我不知道如何将它们与PreparedStatements的常规设置一起使用。所有时髦的问号。我不断得到经典:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:Cannotaddorupdateachildrow:aforeignkeyconstraintfails(video_game_db.logi

mysql - 数据库迁移 : auto-incremented foreign key trouble

我正在尝试将一些数据从旧的MySQL数据库简单地迁移到新的MySQL数据库。我要迁移的数据来自一个论坛,所以有两个表:threads和posts。在我遇到一些棘手的自动递增外键关系之前,我一直做得很好。数据库架构(简化到重要部分):threads(id,title,user_id,created_at,updated_at)posts(id,thread_id,user_id,body,created_at,updated_at)如您所见,thread_id是一个外键,对应帖子所属线程的id。问题就在这里:新数据库中已经有主题和帖子,并且主键是自动递增。不难看出问题出在哪里:两个数据集

java - hibernate : Foreign key constraint violation problem

我的代码中有一个com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException(使用Hibernate和Spring),我不知道为什么。我的实体是Corpus和Semspace,并且在我的hibernate映射配置中定义了从Semspace到Corpus的多对一关系:[...]产生异常的Java代码是:Corpuscorpus=Spring.getCorpusDAO().getCorpusById(corpusId);Semspacesemspace=newSemspace();semspace.setCorpu