1

I have issue to create custom mysql table from xml schema.

i have create app/code/Vendor_Name/Module_Name/etc/db_schema.xml

db_schema.xml

<?xml version="1.0"?>

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd"> <table name="test_table" resource="default" engine="innodb" comment="Test blog table"> <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true" comment="Entity ID"/> <column xsi:type="varchar" name="title" length="70" nullable="false" comment="Title"/> <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Creation Time"/> <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Update Time"/> <constraint xsi:type="primary" referenceId="PRIMARY"> <column name="entity_id"/> </constraint> </table> </schema>

After this i have execute CLI with no error but can't create db_schema_whitelist.json in Vendor_Name/Module_name/etc folder

php bin/magento setup:db-declaration:generate-whitelist --module-name=VendorName_ModuleName

My vendor_Name/Module_Name is already enable

What i do please help!!!

ketty
  • 107
  • 2
  • 13
  • Does the CLI user has write access to VendorName/ModuleName/etc folder? – John Fonseka Jul 31 '22 at 16:19
  • Yes it has full access – ketty Jul 31 '22 at 16:41
  • Please specify Magento version, I've tested this fragment with 2.4.3 and 2.4.4 and it works properly. To be sure you have properly configured extension. Alternative is try to check comments from https://magento.stackexchange.com/questions/255583/magento-2-is-not-generating-the-db-schema-whitelist-json-file-via-cli (add debug to schema generation) – Victor Tihonchuk Jul 31 '22 at 22:04

1 Answers1

1

Your db_schema.xml is wrong. It has duplicate entries for 'title' column. Remove it and retry. It should work.

This db_schema.xml is working fine.

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="test_table" resource="default" engine="innodb" comment="Test blog table">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true"
                comment="Entity ID"/>
        <column xsi:type="varchar" name="title" length="70" nullable="false" comment="Title"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Creation Time"/>
        <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Update Time"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
    </table>
</schema>

This is the generated db_schema_whitelist.json file

{
    "test_table": {
        "column": {
            "entity_id": true,
            "title": true,
            "created_at": true,
            "updated_at": true
        },
        "constraint": {
            "PRIMARY": true
        }
    }
}

Magento CLI command was

php bin/magento setup:db-declaration:generate-whitelist --module-name=Vendor_Module

If you are still getting an error, then it should be something else. Post the error here.

John Fonseka
  • 246
  • 1
  • 5