【问题标题】:what does sqlstate[42703] mean on heroku?Heroku 上的 sqlstate[42703] 是什么意思?
【发布时间】:2019-02-24 19:43:45
【问题描述】:

我创建了一个 laravel 应用程序,一切都在我的本地主机上正常运行。我正在使用 XAMPP 和 PHPMyAdmin 在本地测试应用程序,当我将其上传到 Heroku 并配置数据库并运行“heroku run php artisan migrate”时,到目前为止没有错误。

我的应用程序是一个简单的表单,用户在其中注册信息并将其存储在数据库中。数据库由一些表组成。这是用户表的迁移

  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: 插入 "competence_profile" ("person_id", “能力”、“年经验”、“更新时间”、“创造时间”) 值(4、设计师、6、2019-02-22 11:36:29、2019-02-22 11:36:29) 返回“id”)。

对于此错误的任何解释或帮助,我将不胜感激。即使在迁移中定义了该列,它也基本上找不到该列。

【问题讨论】:

  • 你有没有发现heroku上的数据库结构和你的localhost很像?
  • SQLSTATE[42703] 表示该列未定义。有用的是它带有纯文本描述:)

标签: php mysql laravel heroku


【解决方案1】:

我找到了一个简单的 SQLState[42703] 解决方案,您可以从 heroku 获得。当您在数据库中有一个表时,heroku 假定该表的主键称为“id”。如果您有一个被调用的主键(在这种情况下,主键称为能力_profile_id),您需要在模型中添加一个具有您拥有的主键值的变量。我在我的能力配置文件模型中将变量命名如下 $primaryKey = 'competence_profile_id';这解决了问题

【讨论】:

    猜你喜欢
    • 2021-11-21
    • 1970-01-01
    • 2013-08-27
    • 2014-11-25
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    相关资源
    最近更新 更多