Hi, so I currently have a table with the following datatypes: column1 -> TEXT column2 -> TEXT column3 -> TEXT
This table is huge, with over 500k+ rows. When I initially started using MySQL on DO, I hardly knew what a primary key was, so I never set one up.
However, I’ve encountered a loop of a problem: In order to set a primary key, I must have a column in the database which has a specific amount of characters, e.g. VARCHAR(10). If I don’t have it, I will get something similar to this:
Error: BLOB/TEXT column 'columnName' used in key specification without a key length
However, in order to even set my column to have a specific key length, I have to modify the table.
As a result, I try to modify the table, using something on the lines of MODIFY TABLE tableName ALTER COLUMN columnName VARCHAR(length). Which tells me that:
Error: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.
Which creates an infinite loop of me not even being able to set a primary key in the first place.
Now I’ve took a look about the possibility of perhaps setting the system variable sql_require_primary_key. However after taking a look at stackoverflow I’ve been suggested it’s not possible to do so.
Can someone help me in this? Thank you.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
You can use the SET SESSION sql_require_primary_key = 0;
It is for a single session though. Once you log out, you would need to run this again before you could do modify the table without primary key.
The below URL has more information on how to create primary keys: