Md. Riaz Rabbi
Md. Riaz Rabbi

Reputation: 1

database error after adding new column

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?

enter image description here

enter image description here

Upvotes: 0

Views: 65

Answers (3)

Asim Shahzad
Asim Shahzad

Reputation: 1609

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

Upvotes: 0

Calin Blaga
Calin Blaga

Reputation: 1373

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.

Upvotes: 1

user2963176
user2963176

Reputation: 74

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

Upvotes: 1

Related Questions