Table already exists error when trying to create user class in springboot

Ariya nazari

So I have already created my database and all the tables with the appropriate columns in Mysql and connected it to springBoot. My issue is that when I create my user class which matches all the right columns on the Mysql setup, and run the springboot application I get: "Error executing DDL...[Table 'users' already exists]" Here is my application.properties setup

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# Hibernate specific properties
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update

and my User class


import jakarta.persistence.*;
@Entity
@Table(name = "Users")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    private String firstName;
    private String lastName;
    private String password;
    private Float rating;

    // getters and setters
}

and my Users table in sql

CREATE TABLE Users (
    User_ID INT AUTO_INCREMENT,
    First_Name VARCHAR(100),
    Last_Name VARCHAR(100),
    Password VARCHAR(255), -- storing hashed password
    Rating FLOAT,
    PRIMARY KEY (User_ID)
);

Can someone guide me as to why this is happening?

yatin tripathi

This error occurs because you have set the spring.jpa.hibernate.ddl-auto property to update, which instructs Hibernate to automatically update the database schema based on the entity classes.

Since the table already exists in the database, Hibernate is trying to execute a DDL (Data Definition Language) statement to create the table again, resulting in the error. To resolve this issue, you have a few options:

  1. Drop the existing table: If you don't have any important data in the "Users" table, you can drop the table from the database and let Hibernate recreate it. Make sure you have a backup of your data if necessary.

  2. Change spring.jpa.hibernate.ddl-auto to validate: By changing the value of this property to validate, Hibernate will only validate the entity mapping against the existing database schema. It won't perform any DDL operations or attempt to create the table again.

    spring.jpa.hibernate.ddl-auto=validate

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Table already exists error when trying to import sql file

Error Users already exits when trying to create a column to an existing table

Error when trying to create a table

PostgreSQL Error: Relation already exists - FOREIGN KEY in CREATE TABLE

mklink error: Cannot create a file when that file already exists

Table already exists error when replacing yaml by XML

Springboot application creating table that already exists in mysql

Error when trying to create an user with JWTAuth in Laravel

Directory error when trying to create a new user

This Row already belongs to another table error when trying to add rows?

Mysql Error 1064 when trying to create a table

SQLAlchemy operational error: no such table column user_id when trying to create new DB row

Refuse to create user if it already exists on database

If project folder with PIPENV is deleted, when trying to create another virtual environment for it, it will tell you it already exists

EF-Core: Table "name" already exists - when trying to update database

Why am I getting a "destination path '.' already exists" error when trying clone from my webfaction server?

"A subdirectory of file txt already exists." error when trying to sort files, even though there are no files name "txt"

Syncdb command in Django 1.6.5 does not create new model class in models.py - says table already exists

trying to persist a class that its related class already exists

Python create directory error Cannot create a file when that file already exists

Key Already Exists in Table when Scaffolding

Golang error for SQL when trying to create a new user

400 error when trying to create a new user via createUser Mutation

Error when trying to insert input from user into SQL table

Azure Function CI Build Error - Cannot create a file when that file already exists

Error Key Already Exists in Table when scaffolding controller vs2015

How to solve "table "auth_permission" already exists" error when the database is shared among two Django projects

Each time I create superuser, Django saves the user but throws an error that user already exists even if it has never existed

Oracle SQL "invalid identifier error" when trying to create a table

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  7. 7

    Do Idle Snowflake Connections Use Cloud Services Credits?

  8. 8

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  9. 9

    Binding element 'string' implicitly has an 'any' type

  10. 10

    BigQuery - concatenate ignoring NULL

  11. 11

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  12. 12

    In Skype, how to block "User requests your details"?

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Pandas - check if dataframe has negative value in any column

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Generate random UUIDv4 with Elm

  17. 17

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  18. 18

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  19. 19

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  20. 20

    EXCEL: Find sum of values in one column with criteria from other column

  21. 21

    How to use merge windows unallocated space into Ubuntu using GParted?

HotTag

Archive