What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello Everyone , In my persistence schema file i am having one unique column name , but i am adding

U029E1DFTRR
U029E1DFTRR Posts: 21 πŸ§‘πŸ»β€πŸš€ - Cadet
edited October 2021 in Slack General

Hello Everyone ,
In my persistence schema file i am having one unique column name , but i am adding one more unique column in existing and run console propel:install .but i am not getting validation on second one which i have added.
This is my existing code

<unique name="pyz_dss_blog-name">
    <unique-column name="name"/>
</unique>

and currently added unique column name

<unique name="pyz_dss_blog-name">
    <unique-column name="name"/>
    <unique-column name="url"/>
</unique>

Comments

  • fsmeier
    fsmeier Senior Software Engineer & Senior Technical Trainer Sprykee Posts: 986 βš–οΈ - Guardians (admin)

    Heyhey, do you want to have uniqueness on name+url in combination or everything in column name and everything in column url should be unique?

  • U028VTHNMF1
    U028VTHNMF1 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    I hope, everything in name and everything in URL should be unique

  • U028VTHNMF1
    U028VTHNMF1 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    is this the correct way to add more than one unique constraints

    <unique name="pyz_dss_blog-name">
        <unique-column name="name"/>
        <unique-column name="url"/>
    </unique>
    
  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    no, you need to have separate entries, propel does not support combined keys

  • fsmeier
    fsmeier Senior Software Engineer & Senior Technical Trainer Sprykee Posts: 986 βš–οΈ - Guardians (admin)

    @U028VTHNMF1 isnt it exactly what was posted in the question?

  • U028VTHNMF1
    U028VTHNMF1 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    Actually that was he tend to ask, we need to add more than one unique constraints.

  • fsmeier
    fsmeier Senior Software Engineer & Senior Technical Trainer Sprykee Posts: 986 βš–οΈ - Guardians (admin)

    So depend on what you want you can have either:
    A:

    <unique name="pyz_dss_blog-name-and-url">
        <unique-column name="name"/>
        <unique-column name="url"/>
    </unique>
    

    or B:

    <unique name="pyz_dss_blog-name">
        <unique-column name="name"/>
    </unique>
    <unique name="pyz_dss_blog-url">
        <unique-column name="url"/>
    </unique>
    

    A will check for uniqueness in both columns, so col1+col2 have to be unique in combination. for B the values inside each column have to be unique

  • U028VTHNMF1
    U028VTHNMF1 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    @florian.scholz thanks, I got it from @UKHD8KTMF and created it as like B. The thing is am getting error now on alter table.

  • U028VTHNMF1
    U028VTHNMF1 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    @florian.scholz I dropped the constraints created previously and ran propel install with the option B and am getting error

  • fsmeier
    fsmeier Senior Software Engineer & Senior Technical Trainer Sprykee Posts: 986 βš–οΈ - Guardians (admin)

    Can you paste the content of src/Orm/Propel/Schema/pyz_dss_blog.schema.xml please?

  • U028VTHNMF1
    U028VTHNMF1 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet
    <?xml version="1.0"?>
    <database xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>"
              name="zed"  xsi:noNamespaceSchemaLocation="<http://static.spryker.com/schema-01.xsd>"
              namespace="Orm\Zed\DssBlog\Persistence"
              package="src.Orm.Zed.DssBlog.Persistence">
    
        <table name="dss_post" phpName="DssPost">
            <column name="id_post" required="true" type="INTEGER" autoIncrement="true" primaryKey="true"/>
            <column name="title" required="true" size="255" type="VARCHAR"/>
            <column name="url" required="true" size="255" type="VARCHAR"/>
            <column name="summary" required="true" type="LONGVARCHAR"/>
            <column name="content" required="true" type="LONGVARCHAR"/>
            <column name="author_id" type="INTEGER" required="true"/>
    
            <column name="is_published" type="BOOLEAN" required="true" defaultValue="false"/>
            <column name="created_at" type="TIMESTAMP"/>
            <column name="updated_at" type="TIMESTAMP"/>
            <column name="published_at" type="TIMESTAMP"/>
    
            <unique name="dss_post-title">
                <unique-column name="title" />
            </unique>
    
            <unique name="dss_post-url">
                <unique-column name="url" />
            </unique>
    
            <id-method-parameter value="dss_post_pk_seq"/>
    
        </table>
    
        <table name="dss_post_comment" phpName="DssPostComment">
            <column name="id_post_comment" required="true" type="INTEGER" autoIncrement="true" primaryKey="true"/>
            <column name="fk_post" required="true" type="INTEGER" />
            <column name="content" required="true" type="LONGVARCHAR"/>
            <column name="author_id" type="INTEGER" required="true"/>
    
            <column name="is_published" type="BOOLEAN" required="true" defaultValue="false"/>
            <column name="created_at" type="TIMESTAMP"/>
            <column name="published_at" type="TIMESTAMP"/>
    
            <foreign-key name="dss_post_comment-fk_post" foreignTable="dss_post">
                <reference local="fk_post" foreign="id_post"/>
            </foreign-key>
    
            <id-method-parameter value="dss_post_comment_pk_seq"/>
        </table>
    </database>
    
  • fsmeier
    fsmeier Senior Software Engineer & Senior Technical Trainer Sprykee Posts: 986 βš–οΈ - Guardians (admin)

    Could it be that you have already values inside the table which would break the uniqueness?

  • U028VTHNMF1
    U028VTHNMF1 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    πŸ‘

  • fsmeier
    fsmeier Senior Software Engineer & Senior Technical Trainer Sprykee Posts: 986 βš–οΈ - Guardians (admin)
    edited October 2021

    Is the problem solved now? πŸ‘€

  • U028VTHNMF1
    U028VTHNMF1 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    @florian.scholz yes, thanks a lot.

  • fsmeier
    fsmeier Senior Software Engineer & Senior Technical Trainer Sprykee Posts: 986 βš–οΈ - Guardians (admin)

    perfect! Glad to help