laravel 项目迁移_在Laravel迁移

laravel 项目迁移

Before moving forward we need to know some facts about it,

在继续前进之前,我们需要了解一些事实,

  • Resources: In these directories, we have already a js, lang, sass and view page. Where, sass and js file holf their uncompressed, unminified js, CSS, sass file.

    资源:在这些目录中,我们已经有一个js,lang,sass和view页面。 sass和js文件将其未压缩,最小化的js,CSS和sass文件分开。

  • view/welcome.blade.php: Which is already defined in storage/framwork/views/.... (at the bottom of the page: path/welcome.blade.php)

    view / welcome.blade.php:已在storage / framwork / views / ....中定义(在页面底部:path / welcome.blade.php)

在Laravel迁移 (Migration in Laravel)

We are creating migration for creating databases or Database columns in PHPMyAdmin or any other database. After migration it will be automatically creating a database in PHPMyAdmin means we don't have to create again database and it's columns in PHPMyAdmin.

我们正在创建迁移,以在PHPMyAdmin或任何其他数据库中创建数据库或Database列。 迁移后,它将自动在PHPMyAdmin中创建数据库,这意味着我们不必再次创建数据库,并且它是PHPMyAdmin中的列。

Here, we need to create a post-migration table for creating a table column to store, retrieve, edit and update the data, we can take columns name according to our requirement.

在这里,我们需要创建一个迁移后的表,以创建一个表列来存储,检索,编辑和更新数据,我们可以根据需要获取列名。

First, On CMD run this command for creating a migration table,

首先,在CMD上运行此命令以创建迁移表,

    $ php artisan make:migration create_posts_table

Now, you can see this migration file in this path and open it: database/migration/create_posts_table

现在,您可以在此路径中看到此迁移文件并打开它: database / migration / create_posts_table

Migration in Laravel | Step 1

Here, I am declaring a column name in public function up{ // code }

在这里,我在public function up中声明一个列名{//代码}

Example: Code for create_posts_table

示例:create_posts_table的代码

class CreatePostsTable extends Migration
{
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('body');
            $table->timestamps();
        });
    }
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}

public function up{}: In this function, we are creating a database schema. It is the blueprint of the table that's why we are writing a Blueprint $table in the Schema.

public function up {} :在此函数中,我们正在创建一个数据库模式。 这就是表的蓝图,这就是我们在Schema中编写Blueprint $ table的原因。

public function down{}: In this function, dropIfExists means to drop the table "posts" if already exists.

public function down {} :在此函数中, dropIfExists表示删除表“ posts”(如果已存在)。

Now, again on CMD: $ php artisan migrate

现在,再次在CMD上: $ php artisan migration

Here, this command is used to migrate the table columns successfully. Every migration table has two classes "UP" and "down".

在此,此命令用于成功迁移表列。 每个迁移表都有两个类“ UP”“ down”

  • "UP" class: This method is used to set execution whenever the migration command is running.

    “ UP”类 :每当运行迁移命令时,此方法用于设置执行。

  • "Down" class: This method is used to set when you want to rollback after migration. You can say that it is the reverse of the "UP" method.

    “ Down”类 :此方法用于设置要在迁移后回滚的时间。 您可以说这与“ UP”方法相反。

Now, after migration, we have a new Posts table in PHPMyAdmin's blog' DB table named 'posts'. Again Here, "Posts" is your table name from where you can store, retrieve, delete and update your data.

现在,在迁移之后,我们在PHPMyAdmin的博客“ DB”表中有了一个名为“ posts”的新Posts表。 在这里, “职位”是您的表名,您可以在其中存储,检索,删除和更新数据。

Migration in Laravel | Step 2

Now, here you can see after the migration database id automatically created in the PHPMyAdmin.

现在,在这里您可以看到在PHPMyAdmin中自动创建的迁移数据库ID。

Conclusion:

结论:

In this article, we have learnt about the migration in Laravel. I hope you understood the concept, we will know more about it in the up coming articles. Have a great day! Happy Learning!

在本文中,我们了解了Laravel中迁移 。 希望您理解这个概念,我们将在以后的文章中进一步了解它。 祝你有美好的一天! 学习愉快!

翻译自: https://www.includehelp.com/laravel/migration.aspx

laravel 项目迁移

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值