How do you create a new database table in Magento?

How do you create a new database table in Magento?

Answer: To create a new database table in Magento, follow these steps:

1. Create a Setup Script: In your module, create a `Setup` directory and add a new script inside, typically named `InstallSchema.php` or `UpgradeSchema.php`.

2. Define the Schema: Use the `SchemaSetupInterface` to define your table structure within the `install()` or `upgrade()` method.

3. Run the Upgrade Script: After saving your changes, run the setup upgrade command in the terminal: `php bin/magento setup:upgrade`.

4. Verify the Table: Check your database to ensure the new table has been created successfully.

Make sure to follow Magento’s conventions and coding standards for a smooth integration.

Related Questions & Topics