[Django] #34398: Django should automatically run migrations on in-memory SQLite DB

9 views
Skip to first unread message

Django

unread,
Mar 9, 2023, 2:14:47 PM3/9/23
to django-...@googlegroups.com
#34398: Django should automatically run migrations on in-memory SQLite DB
-------------------------------------+-------------------------------------
Reporter: yamin- | Owner: nobody
oanda |
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) |
Severity: Normal | Keywords: sqlite
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When we use an in-memory SQLite database (for example when running tests
or other purposes), it seems that it's not possible to run the migrations
in a normal way because the in-memory database won't exist in the process
run by `python manage.py migrate`.

Im this case Django should recognize the restriction and run the
migrations automatically.

--
Ticket URL: <https://code.djangoproject.com/ticket/34398>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 9, 2023, 2:31:16 PM3/9/23
to django-...@googlegroups.com
#34398: Django should automatically run migrations on in-memory SQLite DB
-------------------------------------+-------------------------------------
Reporter: Yawar Quadir Amin | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: sqlite | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

Migrations are run automatically when using an in-memory SQLite database
to run the tests. If you're having trouble understanding how Django works,
see TicketClosingReasons/UseSupportChannels for ways to get help.

--
Ticket URL: <https://code.djangoproject.com/ticket/34398#comment:1>

Django

unread,
Mar 9, 2023, 2:34:58 PM3/9/23
to django-...@googlegroups.com
#34398: Django should automatically run migrations on in-memory SQLite DB
-------------------------------------+-------------------------------------
Reporter: Yawar Quadir Amin | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: sqlite | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Yawar Quadir Amin):

OK good to know about the tests. But I'm not just talking about the tests.
If we set up SQLite in-memory database as the 'live' Django database, it
should also run the migrations automatically, no?

--
Ticket URL: <https://code.djangoproject.com/ticket/34398#comment:2>

Django

unread,
Mar 9, 2023, 2:53:34 PM3/9/23
to django-...@googlegroups.com
#34398: Django should automatically run migrations on in-memory SQLite DB
-------------------------------------+-------------------------------------
Reporter: Yawar Quadir Amin | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: sqlite | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:2 Yawar Quadir Amin]:


> If we set up SQLite in-memory database as the 'live' Django database, it
should also run the migrations automatically, no?

I'm not sure how you use SQLite in-memory database in production, but if
you do this you need to handle migrations on your own. For example, by
calling `call_command("migrate", ...)` in your scripts.

--
Ticket URL: <https://code.djangoproject.com/ticket/34398#comment:3>

Django

unread,
Mar 9, 2023, 3:04:23 PM3/9/23
to django-...@googlegroups.com
#34398: Django should automatically run migrations on in-memory SQLite DB
-------------------------------------+-------------------------------------
Reporter: Yawar Quadir Amin | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: sqlite | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Yawar Quadir Amin):

We can use SQLite in-memory DB in production because our database of
record is maintained by another backend service, and the Django app is
just calling out to that service to authenticate users. So the Django DB
doesn't really matter, it's just a local cache.

Anyway, we will use a temp file for now since Django seems to not worry
about this use case ;-)

--
Ticket URL: <https://code.djangoproject.com/ticket/34398#comment:4>

Reply all
Reply to author
Forward
0 new messages