Laravel 5.3 Creating Models Returns “Field doesn't have a default value”

前端 未结 2 1168
独厮守ぢ
独厮守ぢ 2021-01-01 19:40

I\'m using Laravel and Eloquent for two years and today I\'ve decided to install a fresh Laravel 5.3 and try something with it.

I used an old database schema of mine

相关标签:
2条回答
  • 2021-01-01 19:57

    You are trying to insert an object, with no 'URL' attribute, into a table that has a 'URL' column without a default value. So the database can't know what to do with that column.

    You can do one of three things.

    1. Fill in the URL value in the create
    2. Change your schema to allow null insertion on URL
    3. Change the URL schema to include a default value. (empty string)

    Post your migration or schema, if you need further help.

    0 讨论(0)
  • 2021-01-01 20:04

    The reason for the error has been explained by @Nicklas.

    The reason this is happening now, however, is that Laravel 5.3 uses strict mode for MySQL by default.

    If you would like to revert to previous behavior, update your config/database.php file and set 'strict' => false for your connection.

    0 讨论(0)
提交回复
热议问题