search
HomePHP FrameworkLaravelFive steps to use Laravel Migrations

Five steps to use Laravel Migrations

Sep 01, 2021 pm 04:10 PM
laravelmigrationphp

This article is introduced to you by the Laravel tutorial column. The main content is "How to use Migrations in Laravel". I hope it will be helpful to friends in need!

Laravel: Using Migrations

1. First use artisan to create a migratable data table template. After running this command, it will be in the database/migrations directory. Generate a file

php artisan make:migration create_fees_count_table --create=fees_count

2. The generated file contains two methods, up and down. Up contains descriptions of adding tables, adding columns, adding indexes, etc., and down is relatively simple, which is to delete tables. , of course there can be some other logic in it

3. The data table column types supported in up. Make a note and will not translate it for the time being

##$table->bigIncrements('id');Incrementing ID (primary key) using a "UNSIGNED BIG INTEGER" equivalent.$table->bigInteger('votes');BIGINT equivalent for the database.$table->binary('data');BLOB equivalent for the database.##$table->boolean(' confirmed');##$table->char('name', 4);CHAR equivalent with a length.$table->date('created_at');DATE equivalent for the database.$table->dateTime('created_at');DATETIME equivalent for the database.DECIMAL equivalent with a precision and scale.DOUBLE equivalent with precision, 15 digits in total and 8 after the decimal point.ENUM equivalent for the database.FLOAT equivalent for the database. Incrementing ID (primary key) using a "UNSIGNED INTEGER" equivalent.INTEGER equivalent for the database.##$table->json(' options');JSON equivalent for the database.$table->jsonb('options');JSONB equivalent for the database.$table->longText('description');LONGTEXT equivalent for the database. $table->mediumInteger('numbers');MEDIUMINT equivalent for the database.##$table->morphs('taggable');Adds INTEGER taggable_id and STRING taggable_type.$table->nullableTimestamps();Same as timestamps(), except allows NULLs.$table-> ;rememberToken();Adds remember_token as VARCHAR(100) NULL.$table->smallInteger('votes'); SMALLINT equivalent for the database.$table->softDeletes();Adds deleted_at column for soft deletes.$table->string('email');VARCHAR equivalent column.$table->string('name', 100); VARCHAR equivalent with a length.$table->text('description');TEXT equivalent for the database.$table->time('sunrise');TIME equivalent for the database.$table-> ;tinyInteger('numbers');TINYINT equivalent for the database.$table->timestamp('added_on'); TIMESTAMP equivalent for the database.$table->timestamps();Adds created_at and updated_at columns.$table->uuid('id');UUID equivalent for the database.
php artisan  migrate
Command Description
BOOLEAN equivalent for the database.
##$table->decimal('amount', 5 , 2);
$table->double('column', 15, 8);
$table->enum('choices', ['foo', 'bar'] );
$table->float('amount');
$table->increments('id');
$table->integer('votes');
##$table->mediumText('description'); MEDIUMTEXT equivalent for the database.
4. After the table is created, execute it directly. Since I did not use php artisan migrate before creating many tables, running this command directly resulted in a prompt that some tables existed. Therefore, I transferred this file to the tmp directory under the database and added --path 'database/tmp' to the command. The operation is successful again 5. Observe in the database and find that the table has been created!
Related recommendations:

The latest five Laravel video tutorials

The above is the detailed content of Five steps to use Laravel Migrations. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
Full-Stack Development with Laravel: Managing APIs and Frontend LogicFull-Stack Development with Laravel: Managing APIs and Frontend LogicApr 28, 2025 am 12:22 AM

In Laravel full-stack development, effective methods for managing APIs and front-end logic include: 1) using RESTful controllers and resource routing management APIs; 2) processing front-end logic through Blade templates and Vue.js or React; 3) optimizing performance through API versioning and paging; 4) maintaining the separation of back-end and front-end logic to ensure maintainability and scalability.

Lost in Translation: Cultural Nuances and Misunderstandings in Distributed TeamsLost in Translation: Cultural Nuances and Misunderstandings in Distributed TeamsApr 28, 2025 am 12:22 AM

Totackleculturalintricaciesindistributedteams,fosteranenvironmentcelebratingdifferences,bemindfulofcommunication,andusetoolsforclarity.1)Implementculturalexchangesessionstosharestoriesandtraditions.2)Adjustcommunicationmethodstosuitculturalpreference

Measuring Connection: Analytics and Insights for Remote Communication EffectivenessMeasuring Connection: Analytics and Insights for Remote Communication EffectivenessApr 28, 2025 am 12:16 AM

Toassesstheeffectivenessofremotecommunication,focuson:1)Engagementmetricslikemessagefrequencyandresponsetime,2)Sentimentanalysistogaugeemotionaltone,3)Meetingeffectivenessthroughattendanceandactionitems,and4)Networkanalysistounderstandcommunicationpa

Security Risks in Distributed Teams: Protecting Data in a Remote WorldSecurity Risks in Distributed Teams: Protecting Data in a Remote WorldApr 28, 2025 am 12:11 AM

Toprotectsensitivedataindistributedteams,implementamulti-facetedapproach:1)Useend-to-endencryptionforsecurecommunication,2)Applyrole-basedaccesscontrol(RBAC)tomanagepermissions,3)Encryptdataatrestwithkeymanagementtools,and4)Fosterasecurity-consciousc

Beyond Email: Exploring Modern Communication Platforms for Remote CollaborationBeyond Email: Exploring Modern Communication Platforms for Remote CollaborationApr 28, 2025 am 12:03 AM

No, emailisnotthebostforremotecollaborationToday.Modern platformlack, Microsoft teams, Zoom, ASANA, AndTrelloFhertreal-Time Communication, Project management, Andintegrationfeaturesthancteamworkandefficiency.

Collaborative Document Editing: Streamlining Workflow in Distributed TeamsCollaborative Document Editing: Streamlining Workflow in Distributed TeamsApr 27, 2025 am 12:21 AM

Collaborative document editing is an effective tool for distributed teams to optimize their workflows. It improves communication and project progress through real-time collaboration and feedback loops, and common tools include Google Docs, Microsoft Teams, and Notion. Pay attention to challenges such as version control and learning curve when using it.

How long will the previous Laravel version be supported?How long will the previous Laravel version be supported?Apr 27, 2025 am 12:17 AM

ThepreviousversionofLaravelissupportedwithbugfixesforsixmonthsandsecurityfixesforoneyearafteranewmajorversion'srelease.Understandingthissupporttimelineiscrucialforplanningupgrades,ensuringprojectstability,andleveragingnewfeaturesandsecurityenhancemen

Leveraging Laravel's Features for Both Frontend and Backend DevelopmentLeveraging Laravel's Features for Both Frontend and Backend DevelopmentApr 27, 2025 am 12:16 AM

Laravelcanbeeffectivelyusedforbothfrontendandbackenddevelopment.1)Backend:UtilizeLaravel'sEloquentORMforsimplifieddatabaseinteractions.2)Frontend:LeverageBladetemplatesforcleanHTMLandintegrateVue.jsfordynamicSPAs,ensuringseamlessfrontend-backendinteg

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!