php 工匠,在数据库中创建表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30447385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:47:53  来源:igfitidea点击:

Artisan, creating tables in database

phplaravellaravel-5artisanlaravel-migrations

提问by Streetlamp

I am trying to create mysql tables in Laravel 5. I created a file in /project/database/migrationscalled users.php:

我正在尝试在 Laravel 5 中创建 mysql 表。我创建了一个/project/database/migrations名为的文件users.php

[...]
public function up()
{
    Schema::create('users', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('username');
        $table->string('fullname');
        $table->int('number');
        $table->string('email')->unique();
        $table->string('password', 60);
        $table->rememberToken();
        $table->timestamps();
    });
}
[...]

I then tried running these commands in the project-folder:

然后我尝试在 - 文件project夹中运行这些命令:

$ php artisan migrate
$ php artisan migrate:install
$ php artisan migrate --pretend

None of them return anyoutput and no tables are created. The database to be populated exists.

它们都没有返回任何输出,也没有创建表。要填充的数据库存在。

回答by patricus

Migration files must match the pattern *_*.php, or else they won't be found. Since users.phpdoes not match this pattern (it has no underscore), this file will not be found by the migrator.

迁移文件必须与模式匹配*_*.php,否则将找不到它们。由于users.php与此模式不匹配(它没有下划线),因此迁移器将找不到此文件。

Ideally, you should be creating your migration files using artisan:

理想情况下,您应该使用 artisan 创建迁移文件:

php artisan make:migration create_users_table

This will create the file with the appropriate name, which you can then edit to flesh out your migration. The name will also include the timestamp, to help the migrator determine the order of migrations.

这将创建具有适当名称的文件,然后您可以编辑该文件以充实您的迁移。该名称还将包括时间戳,以帮助迁移器确定迁移顺序。

You can also use the --createor --tableswitches to add a little bit more boilerplate to help get you started:

您还可以使用--create--table开关添加更多样板以帮助您入门:

php artisan make:migration create_users_table --create=users

The documentation on migrations can be found here.

可以在此处找到有关迁移的文档。

回答by Abhishek Sojitra

In order to give a value in the table, we need to give a command:

为了给表中的一个值,我们需要给出一个命令:

php artisan make:migartion create_users_table

and after then this command line

然后这个命令行

php artisan migrate