Home PHP Framework Laravel Five steps to use Laravel Migrations

Five steps to use Laravel Migrations

Sep 01, 2021 pm 04:10 PM
laravel migration php

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
Copy after login

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
Copy after login
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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Apr 18, 2025 am 09:24 AM

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

Laravel user login function Laravel user login function Apr 18, 2025 pm 12:48 PM

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security headers. In addition, the Auth framework also provides functions such as resetting passwords, registering and verifying emails. For details, please refer to the Laravel documentation: https://laravel.com/doc

See all articles