Laravel错误:SQLSTATE [42S22]:找不到列:1054未知列

时间:2016-08-06 16:06:05

标签: php mysql laravel web

我在尝试添加或更新与其他表(telepon)具有一对一关系的表(siswa)中的数据时出现问题,当我提交数据(添加/更新)时,我不断收到此错误SQLSTATE [42S22]:未找到列:1054未知列' nomor_telepon'在' where子句' (SQL:选择count(*)作为web的汇总,其中telepon = 081255758609)。

此处的表siswa迁移代码:

nomor_telepon

表格电传付费迁移代码:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableSiswa extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('siswa', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nisn',4)->unique();
            $table->string('nama_siswa',50);
            $table->date('tanggal_lahir');
            $table->enum('jenis_kelamin',['L','P']);
            $table->integer('id_kelas')->unsigned();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('siswa');
    }
}

Model Siswa代码:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableTelepon extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('telepon', function (Blueprint $table) {
            $table->integer('id_siswa')->unsigned();
            $table->primary('id_siswa');
            $table->foreign('id_siswa')
                    ->references('id')->on('siswa')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');

            $table->string('nomor_telepon')->unique();
            $table->timestamps();


        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('telepon');
    }
}

型号电话代码:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Siswa extends Model
{
    protected $table = 'siswa';

    protected $fillable = [
        'nisn',
        'nama_siswa',
        'tanggal_lahir',
        'jenis_kelamin'
    ];

    protected $dates = ['tanggal_lahir'];

    public function getNamaSiswaAttribute($nama_siswa) 
    {
        return ucwords($nama_siswa);
    }

    public function telepon()
    {
        return $this->hasOne('App\Telepon', 'id_siswa');
    }

    public function kelas()
    {
        return $this->belongsTo('App\Kelas', 'id_kelas');
    }
}

这是我的添加和更新数据方法:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Telepon extends Model
{
    protected $table = 'telepon';

    protected $primaryKey = 'id_siswa';

    protected $fillable = [
        'id_siswa',
        'nomor_telepon',
    ];

    public function siswa()
    {
        return $this->belongsTo('App\Siswa', 'id_siswa');
    }
}

0 个答案:

没有答案