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
1
vote
4 answers

Laravel Breeze not generating migrations

Im following Laravel Breeze Guide from Laravel's oficial page and after installing Breeze package I don't see any new migration these are the lines i executed curl -s https://laravel.build/prueba | bash cd example-app php artisan migrate at…
Davhoj
  • 71
  • 3
1
vote
1 answer

Laravel migration ("SQLSTATE[HY000]: error: 1005 Can't create table `laravel`.`orders` 150 "Foreign key constraint is incorrectly formed" please

public function up() { Schema::create('orders', function (Blueprint $table) { $table->increments('id'); $table->unsignedBigInteger('seller_id'); …
Ritik Rai
  • 11
  • 3
1
vote
1 answer

Laravel migration create custom foreign key

I am creating migration in laravel, where at some point I need to create custom foreign key name in database. I have searched this solution but there is nothing similar to my problem. I want to add columns for names table that contain…
Hemant Kumar
  • 1,025
  • 15
  • 32
1
vote
1 answer

Allowed memory size of 134217728 bytes exhausted (tried to allocate 1052672 bytes)

I had checked for this issue but didn't found the solution that fits my need. I had created the table for State, City & Locality with 37, 7431 & 91853 records are available. It was taking longer time when I was using create instead of using insert…
1
vote
1 answer

Laravel migration errno: 150 "Foreign key constraint is incorrectly formed"

I have a music_upload table which references both album_id and user_id from both album and user table. The user_id foreign key works fine, it is the album_id foreign key which spews out this error SQLSTATE[HY000]: General error: 1005 Can't create…
1
vote
0 answers

How can I run database migrations when using Dusk, Docker, and Laravel?

How can I run my Dusk test using Laravel and Docker? The below solution works when I run migrations from the command line for my test application. Docker + Laravel issue [SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary…
Matt
  • 383
  • 1
  • 5
  • 20
1
vote
2 answers

How to change column length of existing table in SQL?

I have one SQL table which will contain (TEXT/VARCHAR) columns of some length. How can I change the existing column length without dropping or hardcode existing database table. 2020_02_13_065846_create_users_documents_table.php public function up() …
Code cracker
  • 316
  • 1
  • 5
  • 20
1
vote
3 answers

How can i add new column to the all exesting tables in laravel migrations

I have an existing project and now I have to add a new column to all the existing, I have no idea how can I achieve that in Laravel migrations
swatantra
  • 383
  • 1
  • 7
  • 18
1
vote
1 answer

How to add an Array or json type column in laravel migration table?

I want to add a column which is an array or json type by the default it should be an empty if i am not passing any value ,and it should take a value (if i pass any value it should take a value otherwise it should take empty/null value…
Code cracker
  • 316
  • 1
  • 5
  • 20
1
vote
1 answer

Laravel 5.8: General error: 1005 Can't create table

I'm working with Laravel 5.8 to develop my project, and I just create a Migration goes like this: public function up() { Schema::create('user_wallet_transactions', function (Blueprint $table) { $table->bigIncrements('id'); …
user16333885
1
vote
3 answers

Which is the right way to run laravel migrations using Google Cloud Run and Google Cloud SQL

I came here to expose the specific way that i found to run migrations into a Google Cloud Run project using Google Cloud SQL and Laravel, which is simple, i just connect from my .env laravel to Cloud SQL (using Cloud SQL Proxy) and from my local…
1
vote
3 answers

SQLSTATE[HY000] Foreign key constraint is incorrectly formed error in Laravel 8

SQLSTATE[HY000]: General error: 1005 Can't create table laravel.projects (errno: 150 "Foreign key constraint is incorrectly formed") I get the above error when I migrate my projects table and try to join three tables which: A user has many…
Abdullah Al Shahed
  • 89
  • 2
  • 4
  • 19
1
vote
1 answer

Laravel Migration: Error in Json column on Hosting Server but not on Local Xampp Server

I recently downloaded and installed a package for the wallet in which I got migrations published & these migrations have JSON column in some tables. Migration: public function up(): void { Schema::create($this->table(), function (Blueprint…
Hardik Sisodia
  • 615
  • 3
  • 14
  • 37
1
vote
1 answer

Laravel seeder gets stuck and returns ErrorException Array yo string conversion

public function up() { Schema::create('settings', function (Blueprint $table) { $table->id(); $table->string('name', 40)->unique(); $table->json('value'); $table->timestamps(); }); //seeder to insert FTP…
1
vote
1 answer

How to convert string to boolean in laravel migration?

I want to convert a field from string to boolean trying this code: public function up() { Schema::table('users', function (Blueprint $table) { $table->boolean('email_permission')->change(); …
Afshn
  • 323
  • 1
  • 5
  • 16