完整性约束违规:POST上的1452

时间:2014-11-09 22:05:44

标签: php mysql angularjs

我正在尝试通过Angular的Post请求创建记录。我从select中设置的外键。在帖子上我收到此错误

json我发布了

{"customername":"fsdfsf","pan":"sdfsdff","customertype":"sdfsdfsdf","email":"sdfsdf@sdfk.com","mobile":"sdfsdfsdf","offadd":"dfsdfsdf","refererID":1}

错误500内部服务器

"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`auditCrm_db`.`customers`, CONSTRAINT `customers_refererid_foreign` FOREIGN KEY (`refererID`) REFERENCES `referers` (`refererID`)) (SQL: insert into `customers` (`customername`, `pan`, `email`, `mobile`, `offadd`, `updated_at`, `created_at`) values (fsdfsf, sdfsdff, sdfsdf@sdfk.com, sdfsdfsdf, dfsdfsdf, 2014-11-09 21:50:37, 2014-11-09 21:50:37))"

我的角度选择元素

 <select name="refererID" ng-model="customer.refererID" ng-options="referer.refererID*1 as referer.referername for referer in referers " class="" id="selReferer"></select>

我也试过* 1而不是parseint但是同样的结果。

我的架构客户

        $table->increments('customerID');
        $table->string('customername');
        $table->string('pan')->unique();
        $table->string('customertype');
        $table->string('email')->unique();
        $table->string('mobile');
        $table->text('offadd');
        $table->text('comadd');
        $table->string('website');
        $table->string('now');
        $table->string('companyname');
        $table->date('dob');
        $table->integer('refererID')->unsigned()->index();
        $table->foreign('refererID')
                ->references('refererID')->on('referers');
        $table->string('status');
        $table->timestamps();

架构参考

        $table->increments('refererID');
        $table->string('referername');
        $table->string('companyname');
        $table->string('email');
        $table->string('mobile');
        $table->string('offadd');
        $table->string('comadd');
        $table->string('dob');
        $table->string('status');
        $table->timestamps();

发布表单时,我收到此错误。但是,如果我从phpmyadmin插入行创建。如何通过从选择选项中设置值来发布外键。角度选择将有所帮助

0 个答案:

没有答案