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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Stuck on Lesson 9. Keep getting "[User Error] Couldn't run query"


Go to End


6 Posts   815 Views

Avatar
AnimalStripe

Community Member, 14 Posts

25 February 2015 at 5:23am

I'm halfway through the tutorial but unable to progress as I keep getting the following error:

[User Error] Couldn't run query: ALTER TABLE "Region" ADD "PhotoID" int(11) not null default 0, ADD index "PhotoID" ("PhotoID") Duplicate column name 'PhotoID'
GET /example3/dev/build?flush=&=f4889263f3dbd503cfdc1090ca898ae4
Line 598 in /Applications/mampstack-5.4.34-0/apache2/htdocs/example3/framework/model/MySQLDatabase.php

Regions page currently has its two empty class definitions:

<?php

class RegionsPage extends Page {



}

class RegionsPage_Controller extends Page_Controller {

}

…so I assume the problem is with Region.php

<?php 

class Region extends DataObject {


	private static $db = array (
		'Title' => 'Varchar',
		'Description' => 'Text',
		);

	private static $has_one = array (
		'Photo' => 'Image',
		'RegionsPage' => 'RegionsPage'
		);

	public function getCMSFields() {
		$fields = FieldList::create(
			TextField::create('Title'),
			TextareaField::create('Description'),
			$uploader = UploadField::create('Photo')
		);

		$uploader->setFolderName('region-photos');
		$uploader->getValidator()->setAllowedExtensions(array('gif','png','jpg','jpeg'));

		return $fields;

	}

}

…but I can't see any obvious errors and I'm having trouble understanding the debug message. Could someone give me a hand please? Is the problem in plain sight? I've been stuck on this for hours and it's driving me mad!

Avatar
Pyromanik

Community Member, 419 Posts

25 February 2015 at 11:11am

This means that the database table has already had the PhotoID field added to it, but for some reason Silverstripe doesn't think it has, and is trying to add it.
I'm not sure why it's happening, but dropping the affected table should *hopefully* fix it, as the entire thing should be re-generated on the next build.

If not then I'd guess about something with database permissions. But I don't know much about them.

Avatar
AnimalStripe

Community Member, 14 Posts

25 February 2015 at 11:34pm

Dropping the table from the code? I tried that but when I re-introduce it, the same thing happens.

This is really annoying. I'm sure I'm following the tutorial to the letter.

Avatar
Pyromanik

Community Member, 419 Posts

25 February 2015 at 11:51pm

No no, dropping the table from the database.
Don't touch the code.

Avatar
AnimalStripe

Community Member, 14 Posts

26 February 2015 at 1:29am

Ah, I see.

Yep, went into PHP admin and dropped the table. Works fine now.

Thanks!

Avatar
Pyromanik

Community Member, 419 Posts

26 February 2015 at 3:51am

It would be nice to know what caused the issue, but I'm glad to hear it's working now :)