Hot answers tagged

63

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 Edition 2.1.3: Magento CE 2.1.3 consists of 315 tables (that's 18 tables less compared to Magento CE 1.9.2.2). You can find more details about what has changed ...


38

The installer won't run again if it was already executed. Removing the record from setup_module with module = 'MyVendor_Helpdesk' should make it run again.


23

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( 'YOUR_TABLE_NAME', ['YOUR_UNIQUE_FIELD_NAME'], \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE ), ['...


19

The problem here is part of the resource save function magento checks if the primary key is set to auto increment and then removes it from the data being saved if this is the case. In Mage_Core_Model_Resource_Db_Abstract::save you can see how it deals with $this->_isPkAutoIncrement /** * Not auto increment primary key support */ if ($this->...


15

Try this: ->addForeignKey( $installer->getFkName('<ChildTable>', 'entity_id', '<ParentTable>', 'entity_id'), 'entity_id', $installer->getTable('<ParentTable>'), 'entity_id', \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE ) Note: Both table has same field and set primary key to parent table. You ...


14

Try this $connection = Mage::getSingleton('core/resource')->getConnection('core_read'); $sql = "SELECT wishlist_id FROM `customer_wishlists` WHERE `type`='wishlist'"; $rows = $connection->fetchAll($sql); print_r($rows); OR $connection = Mage::getSingleton('core/resource')->getConnection('core_read'); $sql = "SELECT `...


13

EDIT: Just like Magento 1 Anna Völkl created a new version for Magento 2. Check her answer. What you are looking for is an ERD (Entity Relationship Diagram). I have searched for a Magento 2 ERD but could not find and. I think someone from the community will publish one at some point. Here is a blog post which describes the database changes between 1.x and ...


12

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 create the registration.php file in /app/code/VendorName/SysConfigTable <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\...


11

It is fine to change the data type to InnoDB, assuming one of the following is true: You are using MySQL 5.6.4+ where the InnoDB storage engine supports fulltext search You are not using the default Magento Search functionality which relies on underlying MyISAM fulltext search capabilities. That functionality is troublesome to begin with and the feature ...


10

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 permissions errors on var folder. sudo chmod -R 777 var/*


9

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\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; class UpgradeSchema ...


8

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 “Object Manager” object. Right now this object manager is a PHP singleton, which you can grab with the following call. $object_manager = ...


8

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $tableName = $resource->getTableName('employee'); //gives table name with prefix Select Data from table $sql = "Select * FROM " . $...


7

Both methods have the same result. The first one you mentioned was introduces in CE-1.6. In theory that one is the "more correct" than the second one you mentioned second. Let's say that through some magic Magento supports (natively) other db engine than MySQL. If you use the first approach in your extensions you won't have to do anything. The extension will ...


6

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, your next order id will be 1000001.


6

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\Model\ResourceModel\Db\AbstractDb { protected function _construct() { $this->_init('table_name', 'table_pk_id'); $this->...


6

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> <unique_name> <table>your_table_name</table> </unique_name> </entities> Now, check the ...


6

Use \Magento\Framework\App\ResourceConnection class to get resource connection protected $_resource; public function __construct( ... \Magento\Framework\App\ResourceConnection $resource ... ) { $this->_resource = $resource; } /** * $this->_resource = Mage::getSingleton('core/resource'); * $connection = $resource->getConnection('...


5

Your code is correct, what is probably wrong is the order direction. According to Zend_Db_Select::order definition you can pass only one argument, not two arguments as you are doing in your code. Your query will be handled regardless the sorting direction and will take ASC as default. Try changing: ->order('custom_table.custom_row_value','desc'); To ...


5

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 upgrade.


4

Below code is use for creating multiple tables in installer scrips. <?php $installer = $this; $installer->startSetup(); $table = $installer->getConnection() ->newTable($installer->getTable('module_learning/basedata')) ->addColumn('ticket_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( 'identity' => true, ...


4

$collection = Mage::getModel('namespace_module/media')->getCollection(); $collection->getSelect()->join(array('shp'=>'shop_locator_shop'),'shp.shop_id = shop_id'); $collection->getItems(); //return 1052 Column 'shop_id' in on clause is ambiguous This fails because the second shop_id in shp.shop_id = shop_id isn't qualified by a table name. ...


4

The table you are looking for is a simple table. When your host restored your database, it sounds like it did not have the core_store table inside of it. Also, it might be that there is a table prefix that might or might not be at play here. Try these first: Check your database to ensure there is a core_store (or variant) table available. Check to make ...


4

I think this is the problem if (version_compare($context->getVersion(), '1.0.1') == 0) { it should be if (version_compare($context->getVersion(), '1.0.1') < 0) { because when you run the upgradeData file the version is still 1.0.0 and it becomes 1.0.1 only after the upgrade is done.


4

Change your code as below: $Format = $this->_objectManager->create('ChennaiBox\CustomerAccount\Model\Format'); changed to: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $Format = $objectManager->create('ChennaiBox\CustomerAccount\Model\Format'); You have used $this->_objectManager but you have not defined it in ...


4

$cancelId = 5;//id for entry to update $cancel = $this->_cancelFactory->create(); $cancel->load($cancelId); $cancel->setCancelStatus('Review'); $cancel->save(); But as explained in the answers in here: Deprecated save and load methods in Abstract Model, load and save are deprecated. You should create service contracts for your module.


4

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. catalog_product_entity_datetime – Product – date attribute are stored here. Ex: New From, New To catalog_product_entity_decimal – Product price related values. ...


4

(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 table using either of the following SQLs: // The "I'm All In" Approach truncate table reporting_system_updates ; // The "Play It Safe(r)" Approach delete from ...


3

What you're looking for is setMappedTableName. Call this inside your resource model: $this->_resources->setMappedTableName('module_entity1_entity1', 'module_entity1_entity2'); You can put this inside a function then call that before calling the getTable method. Basically, it says that whenever I ask for module_entity1_entity1, give me the ...


3

If you add attributes under Catalog > Manage Attributes > Attributes you can set Visible on Product View Page on Front-end to yes. Now after adding it to the attribute set and adding values per product the attributes and their value should be displayed on the front end on the product page. As to placing them under the description. Normally they would ...


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