Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does db.create_all() check if the database exists?

I checked the docs but it didn't say anything much about it, weirdly.

If I call db.create_all(), does there need to be some sort of check as to whether the database already exists, lest it be overwritten?

like image 436
temporary_user_name Avatar asked Jun 02 '26 07:06

temporary_user_name


1 Answers

The method only creates tables; so it is up to you to make sure the database is already created.

The database has to exist and if the table already exists, you'll receive an error from the database. It will not overwrite or delete tables.

like image 87
Burhan Khalid Avatar answered Jun 06 '26 07:06

Burhan Khalid