Reputation: 1839
I had previously created a table with multiple columns. Among them a "message" column of type longtext
. I want to modify my table by creating an index for the "message"
column. I changed my entity and lunched the command on my bash to update the table. Unfortunately, I got this error message.
An exception occurred while executing 'CREATE INDEX message_idx ON
project (message)':SQLSTATE[42000]: Syntax error or access violation:
1170 BLOB/TEXT column 'message' used in key specification without a key
length
I want to point out that I had been looking for the method to do this kind of operation. And here's what I did on my side.
The index:
* @ORM\Table(indexes={@ORM\Index(name="message_idx",columns={"message"},options={"length"=255})})
The column:
/**
* @var String $message
* @ORM\Column(name="message", type="text",length=255,nullable=true,options={"default": "NULL"})
*/
private $message;
Upvotes: 2
Views: 3251
Reputation: 1462
try with
/**
* @ORM\Entity
* @ORM\Table(indexes={@ORM\Index(name="message_idx",columns={"message"}, options={"length": 255})})
*/
class Test
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="message", type="string", length=255,nullable=true)
*/
private $message;
}
When you use a text type as index you need define a length and 'text' type doesn't have length, so you need use 'string' and length
Upvotes: 2