I want to create a simple entity "mybook" and then I create "mybook" table by following code :

function mybook_schema()
{
	$schema['mybook'] = array(
		'description' => 'the base table for mybook',
			'fields'=>array(
				'bookid' => array(
				'type' => 'serial',
				'unsigned' => TRUE,
				'not null' =>TRUE
				),
			
			'title' => array(
				'type'=>'text',
				'unsigned' => TRUE,
				'not null' =>TRUE),
			
			'price' => array(
				'type' =>'int',
				'not null' => TRUE,
                'default' => 0,
			),
		),
			
		'primary key' => array('bookid')
		
	);
	return $schema;
}

and the mybook_entity_info function() in mybook.module:

function mybook_entity_info()
 {
	 $return['mybook'] = array(
	 'label' => t('My Book'),
	 'uri callback' =>'mybook_uri',
	 'base table'=> 'mybook',
	 'entity keys' => array(
     'id' => 'bookid',
	 'revision' => 'vid',
      'bundle' => '',
      'label' => '',
     ),
	 'static cache' => TRUE,
	 'bundles' => array(),
	 );
	 
	 return $return;
 }

but when I enable "My Book" I get some errors:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned NOT NULL, `price` INT NOT NULL DEFAULT 0, PRIMARY KEY (`bookid`) ) EN' at line 3: CREATE TABLE {mybook} ( `bookid` INT unsigned NOT NULL auto_increment, `title` TEXT unsigned NOT NULL, `price` INT NOT NULL DEFAULT 0, PRIMARY KEY (`bookid`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'the base table for mybook'; Array ( ) in db_create_table() (line 2688 of C:\AppServ\www\drupal-7.12\includes\database\database.inc).

Please help me! Thank alot!

Comments

jaypan’s picture

Textfields cannot be unsigned.

Contact me to contract me for D7 -> D10/11 migrations.

tung_ct’s picture

I'm so negligent.thank u!