Skip to content
Advertisement

Laravel 9.x Terminal can not migrate table

Trying to migrate a users table. Already have 1 table at DB. It’s Contacts for contact form. Trying to migrate a users table. Created my table with terminal $ php artisan make:migration create_users_table
Had the following code in it.

<?php

use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('username')->unique();
            $table->timestamp('email_verified_at')();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
         });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
};

When I tried to migrate the table terminal returns an error.

I run php artisan migrate and it returns Migrating: create_contacts_table

“I’m trying to migrate users table and because of the contacts table already exist it says table already exists : 1050 ...

Tried to give an argument as it said on the website but didn’t work either. I tried this $ php artisan migrate [--path[C:xampphtdocscustomdatabasemigrations2022_05_03_121341_create_users_table.php]]

but it returned No arguments expected for ‘migrate’ command

How can I change the directory of migrate command? Or how can I solve this problem.

Advertisement

Answer

so first change timestamp line and put this line:

$table->timestamp('email_verified_at')->nullable();

then in command line use:

php artisan migrate:fresh
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement