MySQL Workbench auto increment disabled - mysql

I am using Workbench version 6.3.5 Community and this is GUI question only.
When creating a new table auto increment check-box is disabled.
Is it a bug or I need to enable this some how in options?
And how to set start value and step for auto increment in GUI when creating a table?

You need to set auto increment in table

As a work around, when you click the 'Apply' button and are presented with the generated script to review, you can actually edit that script. I ran into the issue you posted as well and just manually added AUTO_INCREMENT to the column definition I needed it applied to.

You can do it this way
Halil Saltik

Just check the AI(Auto Increment) checkbox. No work around, that's why it's a workbench. Life made easy

Make sure the datatype is INT, not character based.

If you are like me, and you are wondering how on earth to get to that primary-key, auto-increment checkbox etc:
Hover over the table name, in my example "persons"
A "spanner like icon" will appear
Click on it and that's it!
I am using MySQL Workbench 8.0 CE(v8.0.19)

The field must be both datatype int and the primary key for the table.

Related

Reset autoincrement in mysql

I'm running my DB on MYSQL community version 8.0.20. I want to reset a column's autoincrement value back to 1. I looked around and tried doing this
ALTER TABLE table_name AUTO_INCREMENT = value;
but it didn't work. I read that there's no actual way to reset the autoincrement value and that makes sense as it would affect data integrity. But I wanted to use this for a table that has no dependencies at all. How can I reset the value? I was thinking of dropping and recreating the table exactly as it is with all of it's columns and types (I don't need to retain the records)
Is there really a way to reset the auto increment value directly? If not, what is the easiest way I can drop and recreate the table in MYSQL Workbench.

MySQL Workbench doesn't show columns when I alter the table

I have the table "giorno",I want to alter it but no columns are showed and I can't even add a new column because the existing columns are not shown either, se the screenshot below:
I also tried to create a new table but it appears the same bug. So I can't add new columns.
How is it possible? Maybe I made a mistake with my settings?
Just in case anyone else runs into this. Just click the arrow on the top right (next to schema).
On the right of your screen i can see two scrollbar arrows. Please try to place your mouse pointer there and resize the window.(Its in the same line with the Column Name,Datatype,PK...)
I think there's a bug. I had the same issue, but it was stopping after a
timestamp(6) / on update CURRENT_TIMESTAMP(6)
field. I had to change it to a straight date(6) field with no on update clause, and the rest of the fields then appeared.
After that, I went back and changed my field back to timestamp(6) / on update CURRENT_TIMESTAMP(6) and the table editor displayed everything correctly.
I found the solution. I have 3 tables and any of them has a primary key. I just changed one key from Primary to Index and now everything is working.
For me restarting the workbench solved the problem!

"Table already exists" when changing PK autoincrement in MySQL

I am quite new to MySQL and I have encountered a problem that I find quite puzzling. If I create a table with MySQL Workbench, when I set the PK I can choose it to auto-increment or not, as should be. However, if I change my mind later on, once the table has been created, I cannot alter the auto-increment flag any longer, as MySQL tells me that the "table already exists". That happens even if the table is empty.
The auto-generated SQL is as follows:
ALTER TABLE tablename
CHANGE COLUMN `ID` `ID` INT(11) NOT NULL AUTO_INCREMENT ;
and it fails with the error stated above. I have tried changing the algorithm and lock type, to no avail.
This does not happens in T-SQL or Oracle, for instance, so I fail to see a reason why it should fail in MySQL. Is there any way to fix this without having to drop and re-create the table?
Thanks.
From experience all the GUIs get a bit confused when you start changing primary keys, the number of error messages I've seen from SQL Server...
You don't need to drop the whole table, but it might be easiest to drop and then re-create the offending column.
Also, check out the MySQL dev docs, but I think either ALTER or MODIFY column are the two I'd go for and I'm not sure why the column name is there twice if you're not renaming it.
Ok, I discovered the culprit thanks to dbForge Studio. The same thing happens there, but this time the error is more explicit: I cannot change the auto-increment flag apparently because it is used as a foreign key on another table. I deleted the FK and then I was able to set the auto-increment.
Thank you all who helped me, I have learned some new things thanks to your comments.

AUTOINCREMENT not automatically adding values in Mysql Workbench IDE

I am learning to use MYSQL-Workbench for inserting data into tables
My Problem::
I have two columns one for Sl_no and one for Name
Sl_no is the primary key which has auto increment checked as shown in
snapshot-1
If you look at Snapshot-2 auto_increment is not automatically
incremented when i keep adding the values
should i need to enable any option for this ?
Because Using the IDE should automatically add values(Since Sl_NO has
autoincrement enabled) but it is not doing so
I have to manually add it one after another
Snapshot-1
Snapshot-2
How can i resolve this ?
{EDIT}
I am using Windows-7 OS
As you can see i am clicking the marked area in the pic to apply
changes, but nothing is happening.
Should i need to enable any settings
UPDATE: It wasn't apparent right away that you're doing this from model and not directly in your db table.
To create your schema from model you need to do Forward Engineering and in the dialog choose Generate INSERT Statements for Tables.
Then go to the object browser in your MySQL connection, not your model. Fire select statement in query window or choose from context menu Select Rows - LIMIT 1000 and you'll see that your sl_no column is populated as expected.
BTW both mac and windows interfaces are identical.
Original answer:
You forgot to commit your changes by clicking Apply
And after reviewing the change script click Apply again.
After that you'll see your auto_increment column values populated

How to add on delete cascade and on update restrict using phpmyadmin?

I want to add 'On delete cascade and on update restrict' on foreign keys through phpmyadmin user Interface instead of executing query.
I generally use Heidisql control panel for doing these actions. And now I'm having hard time doing the same on phpmyadmin.
Any idea?
In the tab where you define the table structure, you get the list of columns and their properties and underneath that there should be a link "relation view", between "print view", and "propose table structure."
That's where you want to go, but you have to have created the index on both tables already.
Also, you might want to make sure you're using mysql's innoDB storage engine.
Edit : An image is worth 1000 words :
Cimbali's answer worked for me, but things were placed a little differently, so in case you're also looking for the "relation view" link, try looking there:
It should take you there:
Key fact:
1. Both table must be have innodb storage engine.
2. The datatype and length should be same in both table.
3. The field in 2nd table should be created as index.
Hope it will help someone...