Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

constraint "SiteTree_ClassName_check" is violated by some row


Reply


5 Posts   1701 Views

Avatar
Imbrondir

Community Member, 13 Posts

3 July 2011 at 2:58am

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.

Avatar
Sphere

Community Member, 44 Posts

3 July 2011 at 3:21am

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

Avatar
Imbrondir

Community Member, 13 Posts

3 July 2011 at 5:10am

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?

Avatar
Imbrondir

Community Member, 13 Posts

3 July 2011 at 7:19am

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

Avatar
Imbrondir

Community Member, 13 Posts

3 July 2011 at 9:04am

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.