Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用laravel 5在表上创建一个新的字符串列_Php_Laravel_Mariadb - Fatal编程技术网

Php 使用laravel 5在表上创建一个新的字符串列

Php 使用laravel 5在表上创建一个新的字符串列,php,laravel,mariadb,Php,Laravel,Mariadb,希望你做得很好,我实际上有一个php函数,它在表上创建一个新的整数(4字节)列,而我希望我的函数在我的MariaDB表上创建一个字符串列 谢谢(如果你需要更多信息,我整天都在你身边) 以下是引用此帖子下代码的代码: <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;

希望你做得很好,我实际上有一个php函数,它在表上创建一个新的整数(4字节)列,而我希望我的函数在我的MariaDB表上创建一个字符串列

谢谢(如果你需要更多信息,我整天都在你身边)

以下是引用此帖子下代码的代码:

 <?php

 use Illuminate\Support\Facades\Schema;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Database\Migrations\Migration;

  class CreateConsultantsTable extends Migration
 {
/**
 * Run the migrations.
 *
 * @return void
 */
    public function up()
    {
    Schema::create('consultants', function (Blueprint $table) {
        $table->increments('id');

        $table->integer('business_id')->unsigned()->nullable();
        $table->foreign('business_id')
            ->references('id')->on('businesses');

        $table->string('trigram')->unique();

        $table->date('availability')
            ->nullable();

        $table->integer('years_experience')->nullable();

所以,使用Laravel很容易

在这里,您可以看到如何生成用于执行此方法的迁移

假设您想向users-table添加一个shortname字段

打开
2017\u 12\u 04\u 104053\u add\u shortname\u to\u users\u table.php
(之前的日期将是另一个日期)

所以,最后只需更新up方法


运行您的正常迁移,信息就完成了

当我将字符串放入由此函数控制的表单中时,我的控制台中出现了该错误:
422(不可处理实体)
我可以删除现有代码“$table->foreign('business\u id')吗`根据我在下的更新帖子?如果我删除代码,它会自动删除列,或者它会在表中留下一个空列?如果你想删除列,你必须创建一个新的迁移(或使用上面已有的迁移)并运行:
$table->dropColumn('business_id'),它会忽略
 <?php

 use Illuminate\Support\Facades\Schema;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Database\Migrations\Migration;

  class CreateConsultantsTable extends Migration
 {
/**
 * Run the migrations.
 *
 * @return void
 */
    public function up()
    {
    Schema::create('consultants', function (Blueprint $table) {
        $table->increments('id');

        $table->integer('business_id')->unsigned()->nullable();
        $table->foreign('business_id')
            ->references('id')->on('businesses');

        $table->string('trigram')->unique();

        $table->date('availability')
            ->nullable();

        $table->integer('years_experience')->nullable();
php artisan make:migration add_shortname_to_users_table --table=users
$table->string('shortname');