laravel을 사용하여 기본 테이블 또는 뷰를 찾을 수없는 데이터베이스 테이블을 수정하는 방법

DevGe

나는 일반적인 오류가 있으며이 문제에 대해 내가 무엇을 불렀는지 모르겠습니다. 그래서 제가 직면 한 문제를 설명해 드리겠습니다.

그래서 지금은 laravel 5.7을 사용하고 있으며 여러 인증 가드를 수행했습니다. 그래서 지금은 영업 사원에 대한 로그인이 있으므로 모든 영업 사원 사용자를위한 마이그레이션 테이블을 만들었습니다. 그래서 이미 2020_05_16_190202_create_salesperson_table.php를 성공적으로 데이터베이스에 마이그레이션 했습니다 .

로그인 후 발생하는 오류로 이동하겠습니다. sales_person 테이블이 있습니다. 제출 버튼을 클릭 한 후 오류가 발생하고 오류가 기본 테이블 또는 뷰를 찾을 수 없음 : 1146 테이블 'dbname.sales_people'이 존재하지 않습니다 (SQL : select * from sales_peoplewhere email= [email protected] limit 1).

내 앱 / 영업 담당자가 sales_people을 찾는 이유는 무엇입니까? 데이터베이스에 sales_people 테이블이 없습니다. 나는 sales_person 만 있습니다. 그래서 나는이 오류가 왜 나에게 주는지 이해하지 못합니다.

문제 : 내 앱 / 영업 담당자가 마이그레이션을 위해 생성되지 않은 sales_people 테이블을 찾는 이유는 무엇입니까?

모델:

   <?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;


class SalesPerson extends Authenticatable
{
    use Notifiable;

    protected $guard = 'salesperson';

    protected $fillable = [
        'first_name', 
        'middle_name', 
        'last_name', 
        'email', 
        'password', 
        'mothers_maiden_name', 
        'emergency_contact',
        'emergency_contact_num',
        'address',
        'tin_num',
        'valid_photo',
        'parent_id',
        'created_at'
    ];

    protected $hidden = [
    'password', 'remember_token',
    ];
}

이주:

   <?php

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

class CreateSalespersonTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('salesperson', function (Blueprint $table) {
            $table->increments('id');
            $table->string('first_name');
            $table->string('middle_name');
            $table->string('last_name');
            $table->string('email');
            $table->string('password');
            $table->string('mothers_maiden_name');
            $table->string('emergency_contact');
            $table->string('emergency_contact_num');
            $table->string('address');
            $table->string('tin_num');
            $table->string('valid_photo');
            $table->enum('member_status', array('Active','Pending'))->default('Pending');
            $table->string('parent_id');
            $table->string('sponsor_id');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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

DB 테이블 :

표

porloscerros Ψ

Eloquent 모델 규약

테이블 이름

우리 SalesPerson모델에 어떤 테이블을 사용할지 Eloquent에 알려주지 않았습니다 . 관례 적으로 "snake case"는 다른 이름이 명시 적으로 지정되지 않는 한 클래스의 복수 이름이 테이블 이름으로 사용됩니다. 따라서이 경우 Eloquent는 SalesPerson모델이 sales_persons테이블에 레코드를 저장 한다고 가정 합니다. 모델에서 테이블 속성을 정의하여 사용자 지정 테이블을 지정할 수 있습니다.

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class SalesPerson extends Authenticatable
{
    use Notifiable;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'salesperson';

    // ... everything else you already have
}

규칙을 따르도록 테이블의 이름을 변경할 수도 있습니다. 그러면 모델에서 명시 적으로 만들 필요가 없습니다.

Schema::create('sales_persons', function (Blueprint $table) {
    // ...
});

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관