I had created a login and register form. But I forgot to add a column. So, I wanted to add a new column named "contactNumber". For adding the column, I wrote a command named php artisan migrate:refresh in cmd.exe and also write a code at create_users_table in migration folder. But, the new column's value doesn't go to mysql database. What am I doing wrong?
Asked
Active
Viewed 56 times
3 Answers
1
You need to add your new column to your model, so in your User class you need to do this:
protected $fillable = [
'name', 'email', 'password', 'contactNumber'
];
Hope this help

user2963176
- 64
- 1
- 5
1
You're trying to insert a new record in the database but the contactNumber column doesn't have a default value. In the migration file you can add nullable to that column, eg.
$table->string('contactNumber')->nullable();
or directly in the database from a GUI.

Calin Blaga
- 1,375
- 12
- 19
0
For this type of scenario i personally create new migration like this
php artisan migrate:make add_column_to_table --table="tableName"
Now to run the new migration run this command.
php artisan migrate
This will add new column in your table.Also have a look into this thread. https://laracasts.com/discuss/channels/laravel/add-new-column-to-existing-table

Asim Shahzad
- 1,438
- 11
- 18