Creating an SQLite database?

已回答

I am trying to set up a lightweight local database for my dev environment, just like the db.sqlite3 database you get when creating a new Django project.

However when I try right-clicking on my project and selecting New > Data Source it just doesn't create a SQLite database. It creates a sql file to execute statements.

How can I just create a database from PyCharm?

0

Hi Pablo. I see how our wording might be confusing. What we actually let you create is a connection to an existing database. Thus, you need to arrange for your SQLite database to be created by your application.

This can be done pretty easily with frameworks such as SQLAlchemy.

0
Avatar
Permanently deleted user

Thanks for your answe! But I don't follow. What do I need to set up?

Let me explain in more detail: I cloned an existing project that uses postgresql but I don't really need/want to set up a postgresql because I think it's just simpler and more than enough to work with a sqlite3 db in a dev envirionment.

So what I did is I configured the database in the settings file:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

But how do I actually produce the db.sqlite3 file? As I said, in a scaffolded Django project it just comes with it (and it's marked as a data source), but since I don't originally have it, what should I do?

0

Your Django scaffold should have a console command that creates the database and all the tables in the database. That isn't the kind of thing you want to do manually, as it isn't repeatable.

0
Avatar
Permanently deleted user

I was walking about the clean scaffold that's used in the tutorial (https://docs.djangoproject.com/en/1.10/intro/tutorial01/). Maybe when I run a migration the sqlite database will be automatically created?

0

Yes, follow the tutorial with your modification for the database (PG -> sqlite) and once you reach the point that a sqlite file is created, then you can use PyCharm's data source. It is important to let your software manage the creation/modification of your database and schema.

0
Avatar
Permanently deleted user

Ok thank you very much, I hope that will work as expected!

0

请先登录再写评论。