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

I got error while migrating laravel migrations in arch linux

Illuminate\Database\QueryException could not find driver (Connection: mysql, SQL: create table migrations` (`id` int unsigned not null auto_increment primary key, migration` varchar(255) not null, `batch` int not null) default character set…
Boburjon
  • 23
  • 4
-1
votes
1 answer

Foreign key constraint is incorrectly formed (with inno db)

When running: Schema::create('files', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->id(); $table->string('path'); $table->timestamps(); }); Schema::create('file_users', function (Blueprint $table) { $table->engine =…
echocage
  • 1
  • 1
  • 3
-1
votes
1 answer

How can I in migration to set index name automatically manually?

In laravel 9 app running migration with statement(mysql database) : $table->foreignId('notification_config_id') ->nullable() ->references('id') ->on('notification_configs') ->onUpdate('RESTRICT') ->onDelete('RESTRICT'); I got error…
mstdmstd
  • 2,195
  • 17
  • 63
  • 140
-1
votes
1 answer

Laravel - does migrate command work with folders?

I've made a migration in a folder and when I run php artisan migrate nothing happens. I do not want to specify a certain folder every time to run migrations so I am not sure what the error is. I do not see the migration in the migrations table. here…
ODelibalta
  • 2,194
  • 1
  • 18
  • 28
-1
votes
1 answer

Laravel migration failing with foreign keys

In my Laravel 8.x project I have this table structure: plays +--------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra …
netdjw
  • 5,419
  • 21
  • 88
  • 162
-1
votes
2 answers

Laravel 5.4: SQLSTATE[HY000]: General error: 1005 Can't create table "Foreign key constraint is incorrectly formed"

I'm using Laravel 5.4 and I have added this Migration: public function up() { Schema::create('episodes', function (Blueprint $table) { $table->increments('id'); $table->integer('course_id')->unsigned(); …
memite7760
  • 69
  • 9
-1
votes
1 answer

Laravel is unable to identify the data in phpmyadmin

I use Laravel When I try to access Localhost:8000 I get an error Illuminate\Database\QueryException SQLSTATE[HY000] [1049] Unknown database 'my_data' (SQL: select `title`,`id` from `table_8` where `id` = 24) I have a database called…
-1
votes
1 answer

How to search a value from DB with float value in laravel?

I am developing one API which is responsible for searching with float values like 99.99 or 67.00.....,Below query should get the data if we enter 9999 inorder to 99.99,but i need to show results if the user search with the 99.99…
Sai Tarun
  • 569
  • 4
  • 14
-1
votes
3 answers

: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails in laravel migration

In my migration file , I am adding organization id to the user's table , i tried all of the code below but not solved yet class AddOrganizationIdToUsersTable extends Migration { /** * Run the migrations. * * @return void */ …
swatantra
  • 383
  • 1
  • 7
  • 18
-1
votes
2 answers

How to rename a existing table name inside database in laravel-8?

I developed one api which is responsible for storing user details inside my database ,The table name is users_containers, it will contain some users data now i want to rename that table name to users_data without lossing any data ,How to acheive…
Devops Training
  • 221
  • 3
  • 15
-1
votes
1 answer

Laravel migration works on Linux but not on windows

When I try to run my Laravel migration on windows this is the migration file that fails on Windows but works on Linux.
-1
votes
1 answer

SQLSTATE[42S02]: Base tableor view not found:1146 Table 'tienda.productos' doesn't exist

I have tried to change the static $rules, but then the controller code no longer works for me. I have also tried to delete it, but I did not insert records into the table. So it allows because I get another error due to the lack of static…
-1
votes
1 answer

Write Laravel Migration to create postgres table column with data type point for to store latitude longitude (coordinates)

How to write laravel migration to create column with point data type without postGIS extension
-1
votes
1 answer

Laravel Migration: Creating 2 tables Users Table & Advertisements Table (with foreign key referring to user's id)

I'am trying to create Advertisement table which contain 'user_id' column referencing to 'id' column in users table, but with no luck. as of the error message, i noticed that framework not passing column 'id' of the users table. Knowing i manged to…
Salim
  • 62
  • 1
  • 8
-1
votes
1 answer

QLSTATE[HY000] [2002] Connection refused (SQL: select * from inform)

I got an error: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = lar1 and table_name = migrations and table_type = 'BASE TABLE') when I replace DB_HOST with localhost an error will…
pandu
  • 1
  • 1
1 2 3
32
33