Django Project Djaunty rent a bike

Hello,

I starded yesterday the project and everything was working till the creation of the bikes on Shell (question 17).
I stopped and today, I can’t access to the database anymore and when I want to do migrations again I have this long error message:

$ python3 manage.py migrate
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 82, in _execute
return self.cursor.execute(sql)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/sqlite3/base.py”, line 411, in execute
return Database.Cursor.execute(self, query)
sqlite3.DatabaseError: database disk image is malformed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “manage.py”, line 22, in
main()
File “manage.py”, line 18, in main
execute_from_command_line(sys.argv)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/init.py”, line 401, in execute_from_command_line
utility.execute()
File “/usr/local/lib/python3.6/dist-packages/django/core/management/init.py”, line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/base.py”, line 330, in run_from_argv
self.execute(*args, **cmd_options)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/base.py”, line 371, in execute
output = self.handle(*args, **options)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/base.py”, line 85, in wrapped
res = handle_func(*args, **kwargs)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/commands/migrate.py”, line 92, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File “/usr/local/lib/python3.6/dist-packages/django/db/migrations/executor.py”, line 18, in init
self.loader = MigrationLoader(self.connection)
File “/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py”, line 53, in init
self.build_graph()
File “/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py”, line 216, in build_graph
self.applied_migrations = recorder.applied_migrations()
File “/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py”, line 77, in applied_migrations
if self.has_table():
File “/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py”, line 56, in has_table
tables = self.connection.introspection.table_names(cursor)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/base/introspection.py”, line 48, in table_names
return get_names(cursor)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/base/introspection.py”, line 43, in get_names
return sorted(ti.name for ti in self.get_table_list(cursor)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/sqlite3/introspection.py”, line 77, in get_table_list
ORDER BY name"“”)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 98, in execute
return super().execute(sql, params)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 84, in _execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.6/dist-packages/django/db/utils.py”, line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 82, in _execute
return self.cursor.execute(sql)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/sqlite3/base.py”, line 411, in execute
return Database.Cursor.execute(self, query)
django.db.utils.DatabaseError: database disk image is malformed
$ python3 manage.py makemigrations
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 82, in _execute
return self.cursor.execute(sql)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/sqlite3/base.py”, line 411, in execute
return Database.Cursor.execute(self, query)
sqlite3.DatabaseError: database disk image is malformed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “manage.py”, line 22, in
main()
File “manage.py”, line 18, in main
execute_from_command_line(sys.argv)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/init.py”, line 401, in execute_from_command_line
utility.execute()
File “/usr/local/lib/python3.6/dist-packages/django/core/management/init.py”, line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/base.py”, line 330, in run_from_argv
self.execute(*args, **cmd_options)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/base.py”, line 371, in execute
output = self.handle(*args, **options)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/base.py”, line 85, in wrapped
res = handle_func(*args, **kwargs)
File “/usr/local/lib/python3.6/dist-packages/django/core/management/commands/makemigrations.py”, line 101, in handle
loader.check_consistent_history(connection)
File “/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py”, line 290, in check_consistent_history
applied = recorder.applied_migrations()
File “/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py”, line 77, in applied_migrations
if self.has_table():
File “/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py”, line 56, in has_table
tables = self.connection.introspection.table_names(cursor)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/base/introspection.py”, line 48, in table_names
return get_names(cursor)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/base/introspection.py”, line 43, in get_names
return sorted(ti.name for ti in self.get_table_list(cursor)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/sqlite3/introspection.py”, line 77, in get_table_list
ORDER BY name"“”)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 98, in execute
return super().execute(sql, params)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 84, in _execute
return self.cursor.execute(sql, params)
File “/usr/local/lib/python3.6/dist-packages/django/db/utils.py”, line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py”, line 82, in _execute
return self.cursor.execute(sql)
File “/usr/local/lib/python3.6/dist-packages/django/db/backends/sqlite3/base.py”, line 411, in execute
return Database.Cursor.execute(self, query)
django.db.utils.DatabaseError: database disk image is malformed.
I don’t know what to do to solve this: it’s an error of database. I don’t understand.

Thank you in advance for your help.

Finally,I started again from the start the project and it worked but when I was to question 20 last rental not saved, the bash terminal started a new session alone and again I have lost all my bikes, renters and rental from the database… It’s not normal that the session closes alone. Is someone else had the same problem?

Had the same problem, looks like the bag is on Codecademy site. if I write the code without the server disconnecting, it’s okay. otherwise, it sends this error.
so copy your code, reset the workspace, and paste it back. should work

1 Like

Hello,
Thank you very much for your answer. I have done the same and it works.