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
1 answer

How to generate completely new migration in laravel 5.2

I am new to Laravel and was working on one project, which was 90% completed, and now project is 100% completed. The project has old Migration files. I have made so many modifications in the tables (added/deleted columns) and/or added new tables in…
Alpesh Trivedi
  • 944
  • 2
  • 13
  • 33
0
votes
1 answer

How to use the password which got generated in Laravel 5.4 into Laravel 5.6

I have a application called A which was developed in Laravel 5.4 and having more than 5000 users. I have to migrate the application to Laravel 5.6 without asking them to change the password.
Albert
  • 174
  • 4
  • 16
0
votes
1 answer

Add multiple rows while migration

I am wondering is there a way to make 10-50 rows as default rows that could be added after migration in database? In case I need to use php artisan migrate:fresh its pain to add simple values over and over again. Like I have Countries table where I…
user8517929
0
votes
1 answer

How to create a MySQL trigger with condition and without delimiter for Laravel migration?

I have a Laravel project that already has a database with an SQL script and I'm trying to put the MySQL script in a migration to use Eloquent instead. My database has triggers that uses DELIMITER $$ and according to this question, it looks like I…
MathieuAuclair
  • 1,229
  • 11
  • 41
0
votes
0 answers

Laravel Routes creating clashes with artisan migrate

Scenario I have setup Laravel application routes in such a way that, where Route::group(["domain" => getSubDomain()->sub_domain,"middleware"=> ["guest"]], function () { //member routes }); have one helper function getSubDomain()->sub_domain,…
Chintan7027
  • 7,115
  • 8
  • 36
  • 50
0
votes
1 answer

Laravel migration value from null to string

I have a DB with a column of null values but now I want to change it for nullable(false). Doing a migration I tried $table->string('route',50)->nullable(false)->default('000 route')->change(); but it says SQLSTATE[01000]: Warning: 1265 Data…
CarlosZ
  • 1,026
  • 1
  • 9
  • 16
0
votes
1 answer

Set an option from a list of options that are valid to use to insert a specific data into database

I am trying to make migration in laravel and I have this condition where a value to be inserted can be either of a number of values from a list, but nothing else outside it. For instance, I have an attribute in database named values and the actual…
0
votes
1 answer

Laravel 5.4 - Error dropping unique constraint on foreign key

I'm trying to drop a unique constraint and I keep running into a foreign key constraint issue: Here's the original migration: Schema::table('table', function (Blueprint $table) { …
0
votes
1 answer

Laravel Relations, Models and Migrations

I have a problem with my relations in laravel: I have two tables, Languages and Customers.The customer just can have 1 language. These are my migrations and Models: Migrations: Schema::create('tbl_customers', function (Blueprint $table){ …
Angel Mora
  • 43
  • 1
  • 5
0
votes
0 answers

How to increase migration and seeding speed in Laravel?

My database migrations and seeding speed is super slow. How to increase the speed of it? I'm frustrated because of this. It takes round about 20 mins for that. I have about 30 migrations and most data types are int,varchar and enum. I realized that…
user1994
  • 477
  • 6
  • 12
0
votes
1 answer

Migration doesn't update database

I have this simple code which when I run - it does not do anything at all. When I migrate, the migration runs - I have feedback from console: Migrated..... But the database stays the same. In migrations table I see my migration, also with a correct…
Epsilon47
  • 768
  • 1
  • 13
  • 28
0
votes
1 answer

Laravel 5.5 - How to create a `negative_id` column value based on `id` value?

I am doing a test, but not sure how to do it with laravel migration file. In short, there is the auto incrementing id field (which will always be a positive integer). But I also want a negative_id field, which would be the value of id * -1, and…
Wonka
  • 8,244
  • 21
  • 73
  • 121
0
votes
0 answers

Laravel Migration - column already exists

Several months ago, I was working late and needed to create a new column for a postgres table. I added the column through the command line using the standard heroku/postgres commands. I quickly realized how silly this was, deleted the column and…
Joshua Foxworth
  • 1,236
  • 1
  • 22
  • 50
0
votes
1 answer

Cannot connect to mysql on php artisan migrate

I'm trying to migrate the migrations I created, but i'm experiencing this error: SQLSTATE[HY000] [1045] Access denied for user 'php'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = php and…
0
votes
1 answer

What wrong with this migration

Hello I am practicing Laravel now and I'm doing some migration but when I try to run my migration I got this following errors. [Illuminate\Database\QueryException] SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child…
Novice
  • 77
  • 2
  • 11