Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
67 votes

Magento 2: Diagram of database tables, such as Orders, Products, etc. and their relationships

More than a year ago I created the database diagram for the Magento Community Edition 1.9.2.2, so it was time to create a new version :-) Here's the database diagram of the latest Magento Community ...
Anna Völkl's user avatar
  • 17.3k
23 votes
Accepted

Magento 2 : How To Create UNIQUE KEY Field in Custom Tabel

You can use Index Type as Old Way: Using setup script \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE To add unique key use code, ->addIndex( $installer->getIdxName( ...
Jaimin Sutariya's user avatar
16 votes

Magento 2 How to add foreign key in update schema

Try this: ->addForeignKey( $installer->getFkName('<ChildTable>', 'entity_id', '<ParentTable>', 'entity_id'), 'entity_id', $installer->getTable('<ParentTable&...
Ronak Chauhan's user avatar
13 votes
Accepted

Magento2: Store Configuration Table with multiple fields

The solution can be found in a module in this Github link. Below you can see how this requirement is created: You must create the following VendorName/SysConfigTable folders in /app/code/. You must ...
St3phan's user avatar
  • 2,907
10 votes

Magento2 InstallSchema.php does not create the table specified

please try the following code. delete from setup_module where module ='module_name'; sudo bin/magento setup:upgrade sudo bin/magento setup:di:compile sudo bin/magento cache:clean if you get any ...
Liz Eipe C's user avatar
  • 1,296
10 votes

Get database connection in magento 2

Use \Magento\Framework\App\ResourceConnection class to get resource connection protected $_resource; public function __construct( ... \Magento\Framework\App\ResourceConnection $resource .....
Prince Patel's user avatar
  • 22.7k
10 votes
Accepted

Get database connection in magento 2

Without a Mage class, how does a developer instantiate model or magento-singleton object? The Mage::getModel and Mage::getSingleton methods have been retired, and in their place Magento has a new “...
Chirag Patel's user avatar
  • 6,136
9 votes

Get database connection in magento 2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $...
Nikunj Vadariya's user avatar
9 votes
Accepted

How to rename an existing custom table in Magento 2?

You can create UpgradeSchema.php file in your module and add below content in that file app/code/Vendor/Module/Setup/UpgradeSchema.php <?php namespace Vendor\Module\Setup; use Magento\...
Kishan Savaliya's user avatar
7 votes
Accepted

Magento 2 "sequence_" tables

I happened to notice this table. In case you're still interested, it records the increment_id for order/invoice/shipment of your store. e.g. Place a new order, it increases by 1. Set it to 1000000, ...
Tienyi Chi's user avatar
6 votes

how to upgrade schema to create new table in existing module in magento 1.9?

It's pretty simple. You will need to edit config.xml and add few files. First, edit your config.xml file: In <entities> section add this: <entities> <...
Adarsh Khatri's user avatar
6 votes

Magento 2 - setup primary key field without auto increment

You need to write this code in your Resource model class $this->_isPkAutoIncrement = false; for example namespace Company\Module\Model\ResourceModel; class Module extends \Magento\Framework\...
Pratik's user avatar
  • 3,805
5 votes
Accepted

New database table best practice: Magento DB or a new DB?

You can have your tables inside Magento db. An upgrade should not destroy custom tables. Usually upgrades add/remove stuff from core tables. Or add more core tables. You should be safe when doing an ...
Marius's user avatar
  • 198k
4 votes
Accepted

How to save data to database in magento 2

Change your code as below: $Format = $this->_objectManager->create('ChennaiBox\CustomerAccount\Model\Format'); changed to: $objectManager = \Magento\Framework\App\ObjectManager::getInstance();...
Prashant Valanda's user avatar
4 votes
Accepted

Update table use where codition(CRUD) - Magento 2

$cancelId = 5;//id for entry to update $cancel = $this->_cancelFactory->create(); $cancel->load($cancelId); $cancel->setCancelStatus('Review'); $cancel->save(); But as explained in the ...
Marius's user avatar
  • 198k
4 votes
Accepted

Magento 1.x Database tables with product data

Main table for products in magento: catalog_product_entity Above table is an act as main table, for that child tables are staring with “catalog_product_entity_” prefix. ...
Prince Patel's user avatar
  • 22.7k
4 votes

Magento 2 How to add foreign key in update schema

Sample for foreign key, <table comment="projectfinder_attributevalue Table" engine="innodb" name="projectfinder_attributevalue" resource="default"> <column comment="Entity Id" identity="...
Kazim Noorani's user avatar
4 votes

reporting_system_updates table is getting large

(TLDR) Simple/Short Answer: Here's a screenshot of the "Official" response I received - from the New Relic Support team: In other words, you can safely delete data in the reporting_system_updates ...
Sharath Kumar's user avatar
4 votes
Accepted

Magento 2 How to create graphql mutation

I have create GraphQl mutation for contact us. Please follow below steps. Step 1 :- You Create registration.php file <?php /** * @author Mohit Patel * @copyright Copyright (c) 2021 * @package ...
Mohit Patel's user avatar
  • 3,833
3 votes
Accepted

SQl is not working?

Try this : $installer = $this; $installer->startSetup(); $installer->run("ALTER TABLE `asm_tracker` CHANGE `create_at` `create_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;"); $installer-&...
Ashish Jagnani's user avatar
3 votes

SQl is not working?

Try below code: $installer = $this; $installer->startSetup(); $installer->run("ALTER TABLE `asm_tracker` CHANGE `create_at` `create_at` TIMESTAMP;"); $installer->run("ALTER TABLE `...
Abdul's user avatar
  • 9,701
3 votes
Accepted

How to set default value in config.xml file for tables in Magento2 backend system configuration

In your case, you can follow the same Magento 1 way, you have to enter a serialized array there. From my experience, the best way to generate that serialized array is to fill in the default data in ...
Khoa TruongDinh's user avatar
3 votes

how to upgrade schema to create new table in existing module in magento 1.9?

create upgrade file. The name of file will be upgrade-yourpreviousversion-updatedversion.php like upgrade-0.1.0-0.1.1.php <?php $installer = $this; $installer->startSetup(); $installer->...
Qaisar Satti's user avatar
  • 32.5k
3 votes
Accepted

Problem in creating a table via custom module ( UpdateSchema.php )

Try below steps. Go to current Magento instances Database and remove the record from setup_module with module = 'Ved_Mymodule'. Remove the cache. Run the command php bin/magento setup:upgrade. Hope ...
Krishna ijjada's user avatar
3 votes

Start with clean database

Try the --cleanup-database in magento command line tool. Documentation
TFS's user avatar
  • 4,319
3 votes

How to insert data into my new create table in any method?

Magento use MVC structure,So you need to create a custom module,which are an installer script and a model First create a database table using installer script. Then create a model for this table. ...
Amit Bera's user avatar
  • 77.5k
3 votes

How to save two entries in one table row in Magento 1.9?

Save those data in array and convert that array to json and you can save that Json in database <?php $jason_data = json_encode($array); ?> after that Save that $jason_data in database ...
Murtuza Zabuawala's user avatar
3 votes

Magento 2 How to add foreign key in update schema

1 more important thing you need to do is make your column in foreign table is THE SAME as the column in your primary table or it will throw an error when you try to run "php bin/magento setup:upgrade",...
fudu's user avatar
  • 1,278
3 votes
Accepted

Magento 2: Is there a way to lock indexer programmatically?

Here is the code which might help you (I took it from \Magento\Indexer\Model\Indexer::reindexAll): $state = $stateFactory->create(); $state->loadByIndexer({indexer_id}); $state->setStatus(...
Andrey Konosov's user avatar
3 votes
Accepted

Magento2: How can I get all orders from database tables

You have to dump for these tables for all orders records: sales_invoice sales_invoice_comment sales_invoice_grid sales_invoice_item sales_invoiced_aggregated sales_invoiced_aggregated_order ...
Hafiz Arslan's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible