Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 回滚mysql表然后再次迁移是否会在保存数据时产生问题?_Php_Mysql_Laravel_Rollback_Migrate - Fatal编程技术网

Php 回滚mysql表然后再次迁移是否会在保存数据时产生问题?

Php 回滚mysql表然后再次迁移是否会在保存数据时产生问题?,php,mysql,laravel,rollback,migrate,Php,Mysql,Laravel,Rollback,Migrate,下面的代码过去可以正常工作,但是在回滚表并再次迁移之后,我遇到了以下错误,我没有对代码做任何更改!。以前有没有人遇到过这种情况: (2/2) QueryException SQLSTATE[HY000]: General error: 1364 Field 'tier_level' doesn't have a default value (SQL: insert into `members` (`ffn`, `title`, `fname`, `mname`, `lname`, `dob`,

下面的代码过去可以正常工作,但是在回滚表并再次迁移之后,我遇到了以下错误,我没有对代码做任何更改!。以前有没有人遇到过这种情况:

(2/2) QueryException
SQLSTATE[HY000]: General error: 1364 Field 'tier_level' doesn't have a default value (SQL: insert into `members` (`ffn`, `title`, `fname`, `mname`, `lname`, `dob`, `nat`, `gender`, `email`, `confemail`, `address`, `city`, `country`, `postcode`, `pobox`, `phone1`, `phone2`, `updated_at`, `created_at`) values (5675675, Mr, john, smith, adam, 1970-01-01, UK, Male, 11, 11, 123, 1111, UK, 222, 333, 123456789, 987654321, 2020-01-26 18:54:53, 2020-01-26 18:54:53))
控制器

public function addContact(Request $request) {
    if ($request->isMethod('post')) {
        $temp1 = 'Temporary';
        $temp2 = 10;
        $newMember = new Member();
        $newMember->title=$request->input('title');
        $newMember->tier_level=$temp1;
        $newMember->fname=$request->input('fname');
        $newMember->mname=$request->input('mname');
        $newMember->lname=$request->input('lname');
        $newMember->dob=$request->input('dob');
        $newMember->nat=$request->input('nat');
        $newMember->gender=$request->input('gender');
        $newMember->email=$request->input('email');
        $newMember->confemail=$request->input('confemail');
        $newMember->address=$request->input('address');
        $newMember->city=$request->input('city');
        $newMember->country=$request->input('country');
        $newMember->postcode=$request->input('postcode');
        $newMember->pobox=$request->input('pobox');
        $newMember->phone1=$request->input('phone1');
        $newMember->phone2=$request->input('phone2');
        $newMember->earned_miles=$temp2;

        $newMember->save();
    }
    return view('add');
}
迁移文件

<?php

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

class CreateMembersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::create('members', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->string('tier_level');
            $table->string('ffn');
            $table->string('fname');
            $table->string('mname');
            $table->string('lname');
            $table->date('dob');
            $table->string('nat');
            $table->string('gender');
            $table->string('email');
            $table->string('confemail');
            $table->string('address');
            $table->string('city');
            $table->string('country');
            $table->string('postcode');
            $table->string('pobox');
            $table->string('phone1');
            $table->string('phone2');
            $table->integer('earned_miles');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */

    public function down()
    {
      //
      Schema::dropIfExists('members');
    }
}

从有限的代码中很难猜测,但我猜您的模型有问题

  • 您的错误是报告它正在尝试插入
    ffn
    (insert语句中的第一个字段),但您没有在
    addContact
    函数中填充它,因此必须在其他位置设置它
  • 这让我想到,您在
    addContact
    中添加的代码不是实际执行并导致错误的代码。因此,首先要检查的是您的模型
  • 检查代码库中的其他位置,查看是否在某个位置设置了
    ffn
    ,以及未引用
    tier\u level
    的位置

这至少会引导您找到正确的区域进行查看。

您的迁移(上下)代码可能不一致。您可以发布迁移文件吗?迁移文件已发布,DigitalDriver