Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » constraint "SiteTree_ClassName_check" is violated by some row

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1456 Views
  • Imbrondir
    Avatar
    Community Member
    13 Posts

    constraint "SiteTree_ClassName_check" is violated by some row Link to this post

    I have a development machine and a production server. I did a lot of changes and upgrades, then when attempting to upload my changes from my development machine and do a dev/build/ I get this:

    http://pastehtml.com/view/az3nbmcc9.html

    In short:
    [Warning] pg_query(): Query failed: ERROR: check constraint "SiteTree_ClassName_check" is violated by some row
    Trace:

    pg_query(Resource id #54,ALTER TABLE "SiteTree" ALTER COLUMN "ClassName" TYPE varchar(255) , ALTER COLUMN "ClassName" DROP DEFAULT, ALTER COLUMN "ClassName" SET default 'SiteTree', DROP CONSTRAINT "SiteTree_ClassName_check", ADD CONSTRAINT "SiteTree_ClassName_check" check ("ClassName" in ('SiteTree', 'Page', 'FCategoryPage', 'FProductPage', 'FTopCategoryPage', 'FishTankHolder', 'HomePage', 'ErrorPage', 'RedirectorPage', 'VirtualPage', 'FishTankPage')))
    Line 187 of PostgreSQLDatabase.php

    I'm no SQL expert, I have no clue what this means.

    I exported the database and download to my computer, which gave the same error there. This is a PostgreSQL database mind you. What is the actual error here?

    And what does the check mean?
    check ("ClassName" in ('SiteTree', 'Page', 'FCategoryPage', 'FProductPage', 'FTopCategoryPage', 'FishTankHolder', 'HomePage', 'ErrorPage', 'RedirectorPage', 'VirtualPage', 'FishTankPage'))
    means That it looks for a column named "ClassName" in each of those tables? In case many of those ain't even a table (like Page) which I suppose is due to not having any extra db fields. And only the 'SiteTree' has a 'ClassName' column.

  • Sphere
    Avatar
    Community Member
    44 Posts

    Re: constraint "SiteTree_ClassName_check" is violated by some row Link to this post

    Did you build the database yourself?
    Seems like something is horribly wrong with you build...

  • Imbrondir
    Avatar
    Community Member
    13 Posts

    Re: constraint "SiteTree_ClassName_check" is violated by some row Link to this post

    Thanks for the reply Sphere.
    But no I've used nothing but the /dev/build/?flush=1 to build my database through the ORM. Any idea what the SQL commands here does?

  • Imbrondir
    Avatar
    Community Member
    13 Posts

    Re: constraint "SiteTree_ClassName_check" is violated by some row Link to this post

    After some time searching, I found this page:
    http://svn.silverstripe.com/open/modules/postgresql/tags/0.9.1/code/PostgreSQLDatabase.php

    with the interesting lines hidden in the comments:

    // SET check constraint (The constraint HAS to be dropped)
             if(!empty($matches[4])) {
                $existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$tableName}_{$colName}_check';")->value();
                //If you run into constraint row violation conflicts, here's how to reset it:
                 //alter table "SiteTree" drop constraint "SiteTree_ClassName_check";
                 //update "SiteTree" set "ClassName"='NewValue' WHERE "ClassName"='OldValue';
                 //Repeat this for _Live and for _versions
                if($existing_constraint){
                   $alterCol .= ",\nDROP CONSTRAINT \"{$tableName}_{$colName}_check\"";
                }
                $alterCol .= ",\nADD CONSTRAINT \"{$tableName}_{$colName}_check\" $matches[4]";
             }

    Looks like that might be my solution. If I only could figure out what I'm supposed to fit into 'NewValue' and 'OldValue'.

  • Imbrondir
    Avatar
    Community Member
    13 Posts

    Re: constraint "SiteTree_ClassName_check" is violated by some row Link to this post

    Well no luck by simply removing the constraints, and I still I have no idea what the developers means by what needs updating. I've tried lots of stuff. But I remembered that I had deleted the ecommerce and payment module (that I had never used) in the same go.

    Adding those modules back improves the situation. Now I can add fields again. However i still get this error message:

    [Warning] pg_query(): Query failed: ERROR: syntax error at or near "FROM" LINE 1: SHOW COLUMNS FROM `Order` LIKE 'Shipping' ^

    In addition to needing to have a lot of buttons from the ecommerce module that I'll never use. An enlightening comment would be extremely welcomed.

    1456 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.