Php sqlstate[42703]在heroku上是什么意思?
我已经创建了一个laravel应用程序,在我的本地主机上一切都正常工作。我正在使用XAMPP和PHPMyAdmin在本地测试应用程序,当我将其上传到Heroku并配置数据库并运行“Heroku运行php artisan迁移”时,到目前为止没有任何错误 我的应用程序是一个简单的表单,用户注册信息并将其存储在数据库中。数据库由一些表组成。下面是users表的迁移Php sqlstate[42703]在heroku上是什么意思?,php,mysql,laravel,heroku,Php,Mysql,Laravel,Heroku,我已经创建了一个laravel应用程序,在我的本地主机上一切都正常工作。我正在使用XAMPP和PHPMyAdmin在本地测试应用程序,当我将其上传到Heroku并配置数据库并运行“Heroku运行php artisan迁移”时,到目前为止没有任何错误 我的应用程序是一个简单的表单,用户注册信息并将其存储在数据库中。数据库由一些表组成。下面是users表的迁移 public function up() { Schema::create('users', function (Blue
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('lastname');
$table->string('username')->uniqe();
$table->string('ssn');
$table->string('lastfour');
$table->unique(array('ssn','lastfour'));
$table->string('email')->unique();
$table->string('role')->default('Applicant');
$table ->foreign('role')
->references('name')
->on('role');
$table->date('applicationDate');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->boolean('application_result')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
以及个人资料迁移
public function up()
{
Schema::create('competence_profile', function (Blueprint $table) {
$table->increments('competence_profile_id');
$table->unsignedInteger('person_id');
$table ->foreign('person_id')
->references('id')
->on('users');
$table->String('competence');
$table ->foreign('competence')
->references('name')
->on('competence');
$table->integer('years_of_experience');
$table->timestamps();
});
}
但是,当我仅在Heroku上将表单提交到数据库时,就出现了错误。如前所述,它在本地运行良好,我可以看到存储在phpmyadmin中的数据。下面是Heroku显示的错误异常
SQLSTATE[42703]:未定义的列:7错误:列“id”不存在
第1行:…t“,”created_at“)值($1、$2、$3、$4、$5)返回
“id”^(SQL:插入到“能力档案”(“人员id”),
“能力”、“工作年限”、“更新时间”、“创建时间”)
数值(4,设计师,62019-02-22 11:36:292019-02-22 11:36:29)
返回“id”)
如果您能对此错误提供任何解释或帮助,我将不胜感激。它基本上无法找到该列,即使它是在迁移中定义的。我找到了SQLState的简单解决方案[42703]从heroku获得。当数据库中有一个表时,heroku会假定该表的主键名为“id”。如果您有一个主键名为“id”(在本例中,主键名为“能力\配置文件\ id”)您需要在模型中添加一个变量,该变量的值为您拥有的主键。我在我的能力配置文件模型中将该变量命名为$primaryKey='competency\u profile\u id';这解决了问题您是否发现heroku上的数据库结构与您的本地主机类似?
SQLSTATE[42703]
表示该列未定义。它附带了一个纯文本说明:)