# Can manage a DB after imported it using inspectdb

**URL:** <https://forum.djangoproject.com/t/can-manage-a-db-after-imported-it-using-inspectdb/1942>\
**Category:** Using Django\
**Created:** [April 13, 2020, 8:14pm UTC](https://forum.djangoproject.com/t/can-manage-a-db-after-imported-it-using-inspectdb/1942 "2020-04-13T20:14:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubenbisneto](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@rubenbisneto](https://forum.djangoproject.com/u/rubenbisneto)\
**Post date:** [April 13, 2020, 8:14pm UTC](https://forum.djangoproject.com/t/can-manage-a-db-after-imported-it-using-inspectdb/1942/1 "2020-04-13T20:14:27Z")

</div>

Hello,

I am not able to manage a database that I created earlier using Django. I’m using a SQLite3 database that I created using the Sqlitestudio application.

I configured my stettings.py as follows:

DATABASES = {  
‘default’: {  
‘ENGINE’: ‘django.db.backends.sqlite3’,  
‘NAME’: os.path.join (BASE\_DIR, ‘rrpm.db’),  
}  
}

I imported the DB using the “inspectdb” command as follows:

$ python manage.py inspectdb\> gcee.models.py

Models.py was created correctly. However I cannot manipulate the DB using the django API, as it presents the following error:

> > > from gcee.models import \*  
> > > cliente = Clientes.objects.get(pk=1)  
> > > Traceback (most recent call last):  
> > > File “”, line 1, in   
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/models/manager.py”, line 82, in manager\_method  
> > > return getattr(self.get\_queryset(), name)(\*args, \*\*kwargs)  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/models/query.py”, line 411, in get  
> > > num = len(clone)  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/models/query.py”, line 258, in **len**  
> > > self.\_fetch\_all()  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/models/query.py”, line 1261, in \_fetch\_all  
> > > self.\_result\_cache = list(self.\_iterable\_class(self))  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/models/query.py”, line 57, in **iter**  
> > > results = compiler.execute\_sql(chunked\_fetch=self.chunked\_fetch, chunk\_size=self.chunk\_size)  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 1151, in execute\_sql  
> > > cursor.execute(sql, params)  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/backends/utils.py”, line 100, in execute  
> > > return super().execute(sql, params)  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/backends/utils.py”, line 68, in execute  
> > > return self.\_execute\_with\_wrappers(sql, params, many=False, executor=self.\_execute)  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/backends/utils.py”, line 77, in \_execute\_with\_wrappers  
> > > return executor(sql, params, many, context)  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/backends/utils.py”, line 86, in \_execute  
> > > return self.cursor.execute(sql, params)  
> > > File “/media/ruben.bisneto@ricoli.local/DADOS/RR ENERGIA/SoftwareDB\_RR/RR-PowerManager/Test/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py”, line 396, in execute  
> > > return Database.Cursor.execute(self, query, params)  
> > > File “/usr/lib/python3.6/sqlite3/dbapi2.py”, line 64, in convert\_date  
> > > return datetime.date(\*map(int, val.split(b"-")))  
> > > ValueError: invalid literal for int() with base 10: b’01/02/2018’

What is going on? What did I do wrong?

---

<div class="post-metadata">

**Author:** ![rubenbisneto](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@rubenbisneto](https://forum.djangoproject.com/u/rubenbisneto)\
**Post date:** [April 13, 2020, 8:16pm UTC](https://forum.djangoproject.com/t/can-manage-a-db-after-imported-it-using-inspectdb/1942/2 "2020-04-13T20:16:50Z")

</div>

Note: This error happened when I was running the python shell using the command:

$ python manage.py shell

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [April 13, 2020, 8:48pm UTC](https://forum.djangoproject.com/t/can-manage-a-db-after-imported-it-using-inspectdb/1942/3 "2020-04-13T20:48:30Z")

</div>

It looks like `inspectdb` has mapped the column containing “01/02/2018” to an `IntegerField` . Try changing the fields on the generated model. You can also comment fields out.

---

<div class="post-metadata">

**Author:** ![rubenbisneto](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@rubenbisneto](https://forum.djangoproject.com/u/rubenbisneto)\
**Post date:** [April 14, 2020, 7:31pm UTC](https://forum.djangoproject.com/t/can-manage-a-db-after-imported-it-using-inspectdb/1942/5 "2020-04-14T19:31:56Z")

</div>

Thank you very much!

The problem was that I filled all dates filed using the format “dd/mm/yyyy” and Django was trying to manipulate it using “yyyy-mm-dd”.

I’ve just manualy made those changes in the DB. But, I was wondering if there is a way to tell python to use the “dd/mm/yyyy” format. Is that possible?

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [April 14, 2020, 8:43pm UTC](https://forum.djangoproject.com/t/can-manage-a-db-after-imported-it-using-inspectdb/1942/6 "2020-04-14T20:43:58Z")

</div>

I think your underlying column is a string (varchar) rather than a date. You should change your database to use a date in the database field. Otherwise, yes there’s a way to tell Django to use “dd/mm/yyyy”, but I believe you’d need to create a custom database field which is a bit of work.
