Closed paolocarrara closed 3 years ago
Sorry, missed the steps to reproduce:
Basically to reproduce, you must start two Laravel applications using sail, previously you must create a network in the docker, place both applications on the same network.
You must create any table with an id in the second application (that is, in the database of the second application), then, in the first application you must create a migration with a foreign key pointing to the id created by the second application.
After the migration is created, trying to perform the migration with the command sail artisan migrate, instead of working and creating a foreign key for the id in the database table of the second application, an error occurs.
Hi there,
Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:
However, this issue will not be locked and everyone is still free to discuss solutions to your problem!
Thanks.
Ok, I already reached those channels, for example https://stackoverflow.com/questions/28950070/is-it-possible-to-reference-a-foreign-key-in-a-different-database-in-laravel.
But given the fact that I did exactly what is needed for this functionality to work and even after that it did not work, I can only assume it is a bug.
I would like to reinforce that I managed to make it work following the stack overflow answer running with php artisan serve, but changing the configuration to run from sail makes the migration brake.
looks like the "issue" here is that cross db fks only work when both dbs are on the same instance of mysql, but sail runs each app with its own independant instance of mysql
in general i would advise against having fk constraints to a different apps database, but if you do want to i expect you will need to manage the setup yourself
Description:
Hello,
I configured two Laravel applications using the sail up command, both have a laravel and mysql instance.
I configured these two applications to belong to the same network.
I can get them to make requests for each other without a problem.
What I would like help with is to make a foreign key reference in a migration. The foreign key must point to the id of a table that is in another database (within the same network).
I found information out there that tells me to do it as follows:
However when I run the command:
I received the following error message:
I would like to know how to set up a foreign key for a table belonging to another database, if anyone can help me I would be very grateful.
I tested it with two separate databases in a local environment as it is the migration and it worked, that is, the problem is happening when using Sail.
Here is the content of the .env file of the first application:
Here is the content of the database.php file of the first application:
Follows the contents of the docker-compose.yml file for each application.
First application:
Second application:
Steps To Reproduce: