In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use Migrations in Laravel. It is very detailed and has a certain reference value. Friends who are interested must finish it!
Laravel: using Migrations
1. First create a transferable data table template using artisan. After the command is run, a file will be generated in the database/migrations directory.
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 and so on. Down is relatively simple, that is, deleting tables. Of course, there can be some other logic in it.
3. Make a comment on the data table column types supported in up. Do not translate for the time being.
CommandDescription$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'); BOOLEAN equivalent for the database.$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.$table- > decimal ('amount', 5,2); DECIMAL equivalent with a precision and scale.$table- > double (' column', 15,8); DOUBLE equivalent with precision, 15 digits in total and 8 after the decimal point.$table- > enum ('choices', [' foo', 'bar']); ENUM equivalent for the database.$table- > float (' amount'); FLOAT equivalent for the database.$table- > increments ('id'); Incrementing ID (primary key) using a "UNSIGNED INTEGER" equivalent.$table- > integer (' votes') 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- > mediumText ('description'); MEDIUMTEXT 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 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.
4. After the table is created, execute it directly. Since many of my previous table creations did not use php artisan migrate, running this command directly prompted the existence of some tables. So, I transferred this file to the tmp directory under database, and added-- path 'database/tmp', to the command successfully again.
Php artisan migrate
5. Observe in the database and find that the table has been created!
The above is all the content of the article "how to use Migrations in Laravel". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 260
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.