Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mrmercan's avatar

Migration error on Forge deployment

I have a migration file for Meeting model. It has user_id foreign key references to users table with code:

$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');

I am trying to deploy latest changes on Forge. It gives me error:

SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'users'

There is migration file for users table in migration folder. Also db has users table. The timestamp of the users migration file is also before the Meetings migration file.

Could you please help me to find why i see this error?

0 likes
8 replies
Sinnbeck's avatar

Do you have multiple databases? The error is quite clear. The users table does not exist in the referenced database

mrmercan's avatar

@Sinnbeck I have a single database and it has a users table with columns id, name etc.

mrmercan's avatar

@mabdullahsari The name of the users table migration file is 2014_10_12_000000_create_users_table.php and the name of the meetings table migration file is 2021_12_27_200254_create_meetings_table.php . Also there is users table in db and it has data. I know the error says it couldnt find the users table. But there is.

mrmercan's avatar

@Sinnbeck Migration file for meetings table.

class CreateMeetingsTable extends Migration
{
    public function up()
    {
        Schema::create('meetings', function (Blueprint $table) {
            $table->id();
			$table->unsignedBigInteger('user_id');
            $table->foreign('user_id')->references('id')->on('users');
            $table->unsignedBigInteger('doctor_id');
            $table->foreign('doctor_id')->references('id')->on('doctors');
            $table->unsignedBigInteger('meeting_type_id');
            $table->foreign('meeting_type_id')->references('id')->on('meeting_types');
            $table->dateTime('date');
            $table->text('note');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('meetings');
    }
}

I ve removed the user_id to try again and this time it gives me reference error for doctors table. There is also doctors table in db.

mabdullahsari's avatar

@mrmercan It's hard to tell what the cause might be.

You should open a support ticket on Forge instead. Kusura bakma, can't help. 🧐

Sinnbeck's avatar

@mrmercan any chance that your migrate command is running with some env flag or similar, making it run on the wrong connection? Did you try ssh into the server and running it manually?

Please or to participate in this conversation.