zoukankan      html  css  js  c++  java
  • laravel中数据库迁移的使用:

    创建数据库迁移文件:

    php artisan make:migration create_links_table

    创建完表之后,设置字段:

     public function up()
        {
            Schema::create('links', function (Blueprint $table) {
                $table->engine="MyISAM";
                $table->increments('links_id');
                $table->string("links_name")->default("")->comment("友情链接的名字");
                $table->string("links_title")->default("")->comment("友情链接的标题");
                $table->string("links_url")->default("")->comment("友情链接的url");
                $table->integer("link_order")->default(0)->comment("友情链接排序");
            });
        }
    
        public function down()
        {
            Schema::dropIfExists('links');
        }
    

    设置完字段之后,在运行数据库迁移文件:

    php artisan migrate

    为创建的数据库迁移文件创建的表填充数据:

    创建数据填充文件:

    php artisan make:seeder LinksTableSeeder

    在文件中填充数据:

     public function run()
        {
            //
            $data=[
                [
                    'links_name'=>"百度",
                    'links_title'=>"百度一下就知道",
                    'links_url'=>"https://www.baidu.com",
                    'links_order'=>1,
                ],
                [
                    'links_name'=>"新浪",
                    'links_title'=>"新浪知天下",
                    'links_url'=>"https://www.sina.com",
                    'links_order'=>2,
                ]
            ];
            DB::table('links')->insert($data);
        }
    

      在DtabaseSeeder中填写:

        public function run()
        {
            $this->call(LinksTableSeeder::class);
        }
    

      

    运行:

    php artisan db:seed

  • 相关阅读:
    bootstrap模态框视频,图片,页面
    curl 的用法指南
    springboot tomcat设置https,springboot配置ssl
    expect脚本
    java8新特性CompletableFuture
    Windows自动备份Oracle数据库
    SQL语句对单个的MySQL存储过程导出
    Oracle表空间的使用
    Oracle数据库基本操作
    Linux 查询 OS、CPU、内存、硬盘信息
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8215264.html
Copyright © 2011-2022 走看看