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!!!

3
  • Does the CLI user has write access to VendorName/ModuleName/etc folder? Jul 31, 2022 at 16:19
  • Yes it has full access
    – ketty
    Jul 31, 2022 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 magento.stackexchange.com/questions/255583/… (add debug to schema generation) Jul 31, 2022 at 22:04

1 Answer 1

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.

4
  • Thanks that's right error in code about <title> tag but still getting same issue
    – ketty
    Jul 31, 2022 at 17:15
  • Check the edited answer. Aug 1, 2022 at 0:40
  • Ok I will try and give feedback
    – ketty
    Aug 1, 2022 at 4:22
  • Thanks that's work...
    – ketty
    Aug 1, 2022 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.