cancel
Showing results for 
Search instead for 
Did you mean: 

Add custom database in custom module

Add custom database in custom module

Hi, 

 

I have created a custom module, I have created a custom database mySQL.

When someone install the module, I would like the database to be installed too. (Like we can do with InstallSchema for add a new table in magento's database.)

It's possible? 

 

Thanks.

 

2 REPLIES 2

Re: Add custom database in custom module

Hi @Juliette_,

You can't create database, but can create table.  for table you can use following way:

If you are using magento 2.3, then you should use db_schema.

You can add/update table using it. 

You need to create a new file db_schema.xml inside you module under etc folder. 

For more info:
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/declarative-schema/db-schema.html

Example:

declarative-schema-in-magento-2-3

You need to run the setup:upgrade command after xml change. 

php bin/magento setup:upgrade


I hope it will help you. 
 

Re: Add custom database in custom module

@Juliette_ 

I doubt it is even possible. There are various reason behind it. Possible solution it to have the user create database with the same name as your module is using, as well as have the same database user assigned which is assigned to Magento database.

 

Above solution is not recommended. Though you are looking for something similar then you can work to get it more streamline.

- Tarandeep
Problem solved?Please give 'Kudos' and accept 'Answer as Solution'.