Contents
해결![notion image](https://inblog.ai/_next/image?url=https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%253A%252F%252Fprod-files-secure.s3.us-west-2.amazonaws.com%252F404a9fb6-ab9b-45cc-8074-ee63a3334890%252F0d11f6f2-5b11-4f11-ab48-f4410d7b4e7c%252FUntitled.png%3Ftable%3Dblock%26id%3D02eb18ee-faef-4e09-995c-1b39ec2382a0%26cache%3Dv2&w=3840&q=75)
insert into user_tb(username, password, email, created_at) values('ssar', '1234', 'ssar@nate.com', now()); insert into user_tb(username, password, email, created_at) values('cos', '1234', 'cos@nate.com', now());
data.sql 에 쿼리문을 작성한 후 서버를 실행하면 다음과 같은 오류가 뜬다.
![notion image](https://inblog.ai/_next/image?url=https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%253A%252F%252Fprod-files-secure.s3.us-west-2.amazonaws.com%252F404a9fb6-ab9b-45cc-8074-ee63a3334890%252Fe5bfaa06-bfcc-4ccc-b29a-69dff787cf98%252FUntitled.png%3Ftable%3Dblock%26id%3D14f6cb07-c9fb-4bf3-8a42-3deadee76b52%26cache%3Dv2&w=3840&q=75)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of class path resource [db/data.sql]: insert into user_tb(username, password, email, created_at) values('ssar', '1234', 'ssar@nate.com', now()); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USER_TB" not found (this database is empty); SQL statement:
Table "USER_TB" not found
테이블이 생성되기 전보다 insert 문이 실행되어서 오류가 발생한다.
해결
![notion image](https://inblog.ai/_next/image?url=https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%253A%252F%252Fprod-files-secure.s3.us-west-2.amazonaws.com%252F404a9fb6-ab9b-45cc-8074-ee63a3334890%252F1c3f58dd-e104-45d5-bcd3-f5a69ba3da5d%252FUntitled.png%3Ftable%3Dblock%26id%3D537b9845-d8ec-4166-a0fa-1f3ea4a2786c%26cache%3Dv2&w=3840&q=75)
defer-datasource-initialization: true
추가Share article