Questions tagged [laravel-migrations]

Database Migrations in Laravel are the way to create and alter database schema.

Introduction

Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application's schema.

Creating Migrations

To create a migration, you may use the make:migration command on the Artisan CLI:

php artisan make:migration create_users_table

The migration will be placed in your database/migrations folder, and will contain a timestamp which allows the framework to determine the order of the migrations.

The --table and --create options may also be used to indicate the name of the table, and whether the migration will be creating a new table:

php artisan make:migration add_votes_to_users_table --table=users

php artisan make:migration create_users_table --create=users

Running Migrations

Running All Outstanding Migrations

php artisan migrate

Note: If you receive a "class not found" error when running migrations, try running the composer dump-autoload command.

Forcing Migrations In Production

Some migration operations are destructive, meaning they may cause you to lose data. In order to protect you from running these commands against your production database, you will be prompted for confirmation before these commands are executed. To force the commands to run without a prompt, use the --force flag:

php artisan migrate --force

Rolling Back Migrations

Rollback The Last Migration Operation:

php artisan migrate:rollback

Rollback all migrations:

php artisan migrate:reset

Rollback all migrations and run them all again:

php artisan migrate:refresh

php artisan migrate:refresh --seed

For more information visit Laravel migrations reference.

489 questions
0
votes
2 answers

laravel models fill additional field inside many-to-many table

I am a newbie at Laravel framework and trying to work me in. I already understand how to generate N:M relationships and handle them inside the models. Now I am asking you how to fill an additional field inside the many to many tables? For…
user1410569
  • 13
  • 1
  • 7
0
votes
1 answer

Laravel Model::find($id) doesn't filter results

I'm trying to edit a column of datatable to show informations in my index view table. This is my controller's method that I call throught Ajax in the view: public function getField(){ // Current User $user_id = \Auth::user()->id; …
0
votes
0 answers

Laravel - migration for data update on production server with unit tests

I wanted to update my existing data that are added through seeds (like change permissions,etc.) on the production server. I've created migration for changing the data as per the requirement. I've also written unit tests for my code that are…
Kapil Verma
  • 178
  • 3
  • 17
0
votes
5 answers

I can not migrate tables again

I deleted all tables in database, but my error is : table.questions exists so I can not migrate them, does it depend on something else as well?
parastoo
  • 2,211
  • 2
  • 21
  • 38
0
votes
1 answer

Receiving [Illuminate\Database\Eloquent\MassAssignmentException] email using Laravel 5.5

Am following a tutorial attempting to learn how to use Laravel5.5. After following a step which said to add protected $fillable = array('email', 'password', 'name'); to the User model. Which I'm assuming is setting which fields are mass assignable…
0
votes
0 answers

How to use Laravel passport if default Laravel auth is not being used

I am using laravel 5.4 and not using the default Auth for user authentication with it. I have created a custom users table and using it with a custom Auth system having all custom middlewares etc. I have thus not run the command php artisan…
Shakti Phartiyal
  • 6,156
  • 3
  • 25
  • 46
0
votes
2 answers

Laravel - How to create database tables

I'm having problems to create database tables. First of all I create the models: php artisan make:model Company -m Second I update the migration company file, adding the columns that I need Third I'm going to phpMyAdmin and create a new database…
user3242861
  • 1,839
  • 12
  • 48
  • 93
0
votes
2 answers

How to generate views from migrations in Laravel?

I am using Laravel 5.4 and the package migrations-generator that generates migrations. So I have the migrations and now I need to generate the views automatically using Artisan. I tried it on Symfony and it was so easy but I can't do it with…
0
votes
3 answers

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…
0
votes
0 answers

Testing Laravel using SQLite migrations breaks on nullable()->change()

My problem is simple. I have a lot of generated migrations from a legacy app that I'm rewriting and while trying to add tests I came across this issue: (I'm running in memory SQLite as the testing DB, with MySQL as the default one) There was 1…
André Castelo
  • 173
  • 1
  • 8
0
votes
3 answers

Table not found when seeding

Below are my migrations The users table have a relation with the customer table In user: $table->integer('customer_id')->unsigned(); $table->foreign('customer_id')->references('id')->on('customers'); When i call php artisan migrate:refresh --seed,…
yooouuri
  • 2,578
  • 10
  • 32
  • 54
0
votes
2 answers

Laravel migrations - foreign key not applying to the table

I have tried add foreign key constraint using migrations. The migration completes without any error. However, when the database is checked, the foreign key constraint is not added to the table. Other things specified in the migrations work fine…
paarandika
  • 1,238
  • 12
  • 21
0
votes
1 answer

Trying to get the username using MODELS but getting this error: Trying to get property of non-object

ERROR: ErrorException in 814a6fb85b2cceb262c3a8191c08e42742940fc7.php line 223: Trying to get property of non-object (View: /var/www/html/m/TS/resources/views/d/show-details.blade.php) Actually I am trying to get the username who has stored the…
asad sajjad
  • 85
  • 2
  • 12
0
votes
11 answers

artisan migrate command doesn't migrate, produces no output

I am working on my first Laravel project. I'm trying to create database migrations and run them with artisan migrate. The migrations aren't running and the command returns no output. Key facts: I used artisan make:migration to create the migration…
Jay Bienvenu
  • 3,069
  • 5
  • 33
  • 44
0
votes
3 answers

php artisan:rollback error in laravel 5.3

I tried building a database where I forgot to place the index of the table. Now I'm trying to rollback the migration but its not working out. It is throwing some error [ErrorException] Undefined index:…
Nitish Kumar
  • 6,054
  • 21
  • 82
  • 148