1
votes

I've dipped my toes into Laravel PHP for the first time, but I hit an issue that I can't seem to figure out. I keep getting the following two error messages when I attempt to post information through a form (using form facade) in an attempt to create a new row in the "files" table.

QueryException in Connection.php line 624: Integrity constraint violation: 19 NOT NULL constraint failed: files.file_description (SQL: insert into "files" ("file_title", "updated_at", "created_at") values (title test, 2015-10-02 00:18:00, 2015-10-02 00:18:00))

PDOException in Connection.php line 362: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: files.file_description (SQL: insert into "files" ("file_title", "updated_at", "created_at") values (tesr, 2015-10-02 00:18:00, 2015-10-02 00:18:00))

The following are my files which relate to this issue. I have populated one row using tinker, and I can edit that row just fine through a form. Creation of new rows through a form seems to be the only issue. I've looked through other threads on this matter, but I'm I haven't found any solutions in the context of my problem. Any help will be greatly appreciated!

UPDATE 1: I've managed slim down the errors to just integrity constraint violations on the file_title value by placing public $timestamps = false; into the file model as per suggested. However, I'm still struggling to fix the constraint violation on the file_title value.

Migration File

class CreateFileManagementTables extends Migration
{

public function up()
{

    Schema::create('files', function (Blueprint $table) {
        $table->increments('id');
        $table->string('file_title');
        $table->string('file_name');
        $table->string('file_description');
        $table->string('file_path');
        $table->nullableTimestamps();
        $table->string('uploader_name');
        $table->double('file_size');
        $table->string('file_type');
    });

}

public function down()
{
    Schema::drop('files');
}
}

Files Model

class File extends Model {

// Mass assignment
protected $fillable = ['file_title', 'file_name', 'file_description', 'file_path', 'uploader_name', 'file_size', 'file_type'];

}

Create Controller Function

public function create()
{
    return view('files.create');
}

Create View

@extends('app')

@section('content')
    <h1>Create a new file</h1>

   {!! Form::open(['url'=>'files']) !!}
   @include('files.form', ['submitButtonText'=>'Create file'])
   {!! Form::close() !!}
@stop
1
What do you want to do with this $table->nullableTimestamps();?aldrin27
At the moment I'm planning on having users upload files, so that nullableTimestamps is there so the server can collect the upload time. I'm also under the impression that you should only specify a name for timestamps when you want user-inputted dates - not sure if that's correct.Tyrx
Is this the default of your timestamps $table->timestamps();?aldrin27
I'm new to phg laravel so I haven't done anything special like specify a DEFAULT clause with it. What you see is what I have - if I misunderstood your question, apologies in advance.Tyrx
Did you overwrite the schema timestamp? using this $table->nullableTimestamps();?aldrin27

1 Answers

1
votes

In your migration file:

public function up() {

  Schema::create('files', function (Blueprint $table) {
    $table->increments('id');
    $table->string('file_title');
    $table->string('file_name');
    $table->string('file_description');
    $table->string('file_path');
    $table->nullableTimestamps(); //set this to default like $table->timestamps();
    $table->string('uploader_name');
    $table->double('file_size');
    $table->string('file_type');
 });
}

In your model:

 class Files extends Model {

  public $timestamps = false; //to disable the timestamp
  // Mass assignment
  protected $fillable = ['file_title', 'file_name', 'file_description', 'file_path', 'uploader_name', 'file_size', 'file_type'];

 }