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

  • 相关阅读:
    Element Form表单验证
    layui table中记住当前页
    Mysql定时任务
    Mysql存储过程
    StringRedisTemplate与redistemplate
    vue路由传值
    背景色渐变(兼容各浏览器)
    用onclick点击框架跳转
    美化滚动条
    图片无缝滚动
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8215264.html
Copyright © 2011-2022 走看看