Yawning Milk Yawning Milk - 1 year ago 168
PHP Question

Edit database column parameters from laravel (tinker)

So I have database with table, where I need to edit one column, make it nullable, to be specific. How can I access it from php artisan tinker, or maybe somehow re-run migration on one table without losing data from it?

Answer Source

With tinker you cannot modify schema table. You need to create a migration like this:


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

class AlterTableUsers extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::table('users', function ($table) {
            $table->string('name', 50)->nullable()->default(null)->change();


In this case, we make name nullable with default value null.

More info: https://laravel.com/docs/master/migrations#modifying-columns

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download