2


I'm using Django for backend, but for some reason, I want to use Laravel beside Django and share the database between them. so the same database for Django and Laravel. but the problem is that Django migrations are not equal to Laravel migrations so the database is different from ( for example constraints and indexes and some other options).
Is this going to break backend if I use Django as the primary database and use Laravel as a secondary backend?
If true, how I can use Django and Laravel in the same database?

2
  • 3
    You can create migrations using either Django or Laravel and use API to transfer data to each other. Commented May 31, 2020 at 10:19
  • @fuddin no I don't want to use API. I want to be separate :) Commented May 31, 2020 at 10:43

1 Answer 1

5

Your database does not depend on Django or Laravel. It just stores data.

Constraints, triggers, indexes, etc are stored on the database itself, and they are completely independent of your framework. Frameworks just abstract the methods and provide easy methods to manage your database. At the core, they use the same commands which are provided by the database. The names of constraints are irrelevant, you can give whatever names you want, frameworks just provide their own uniform naming pattern, which can be customized by the user. So they can be used on both Django and Laravel or any other framework/programming language. That's the main purpose of having a database, to store data in a structured manner so it can be used by any language/framework

Since you already have migrations in Django, there's no need to create the migrations again in laravel. Just reuse the Django database and make your laravel application to properly handle the data (that part is completely in your control)

Sign up to request clarification or add additional context in comments.

4 Comments

sorry, I'm not so familiar with database constraints, so SELECT and INSERT in Laravel or Django will not use constraints to get data? what I mean, for example, we have this foreign key constraint in Django categories_parents_id_6dcc3f37_fk_categories_id, and same table constraints in Laravel is categories_parent_foreign, if I use Laravel form to get data, this will work? what about insert data?
So, no need to create migration files in Laravel? or just create them and not migrate?
@Nimdeveloper, categories_parents_id_6dcc3f37_fk_categories_id and categories_parent_foreign are just names for the foreign key constaints. You can change them to whatever you want, it's functioning won't differ
@Nimdeveloper migration files are basically to create tables. If you already have tables, then there's not really any point in rewriting them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.