0

I'm creating a laravel project that requires multiple databases.These databases are to be populated using laravel migrations.

However, these migrations are to have tables that are the same name on different databases, for eg:

  • table1.users
  • table2.users

The code I am using is as follows:

public function up()
{

    // Core table
    Schema::connection('database1')->create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        // ...
    });


    // table2
    Schema::connection('database2')->create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        //...
    });
}

Laravel stores migrations without any form of connection info/namespacing, meaning that a duplicate error is produced and the migration fails.

Does anyone know of a way of either aliasing or namespacing the table entries?

Thanks in advance

elb98rm
  • 670
  • 6
  • 21
  • can you add the classes name to your post and the error you're getting. – N69S Oct 28 '19 at 09:34
  • `meaning that a duplicate error is produced and the migration fails.` I don't get it. – nmfzone Oct 28 '19 at 12:46
  • When you attempt to migrate two tables with the same name it fails. As pointed out the system was cacheing old versions of the table that clashed, making it seem like the connections are not namespaced.. – elb98rm Oct 29 '19 at 10:16

1 Answers1

0

Scratch this whole question:

The answer to the problem is different to what I hypothesised. It was actually far simpler:

  • The laravel migrations table was not being dropped/rebuilt, thus;
  • old database structures were being persisted

Solution: drop the migrations table manually

elb98rm
  • 670
  • 6
  • 21