Skip to main content

Microsoft Access backend for django.

Project description

=============================

Microsoft Access backend for django

=============================

This project implements a MS Access / MS ACE backend for django.
The database file extension is assumed to be ".accdb".

I thought it would be useful to be able to use Microsoft Access for the purpose of learning django.

In django 5.2.9 and django 6.0.0, we ran the
    "python manage.py runserver"
command and confirmed that the administrator login operation at
    http://localhost:8000/admin/
works.

However, before running the
    "python manage.py createsuperuser"
command, you need to change the value required attributes such as
the [last_login] column in the [auth_user] table.

Do not integrate this software into a production django environment.

SQL statements that do not work will result in an ODBC error. If any SQL statements don't work, please contact me and I'll patch them to make them work. Many SQL statements may not work yet.  
 

Modifications

This project was originally cloned via hg clone
    https://github.com/18F/django-pyodbc-access/
I investigated the reason why it wasn't working by looking at the debug output and applied a patch. There is debug output embedded in the program."DEBUG:True" enables debug output. Normally it is False.There are many _DebugOutput functions in the source program.  
 

"inspectdb command" doesn't work.

The command "python manage.py inspectdb" does not work. The Access database tables must be manually changed into the Django models.py file.  
 

Please change the column attributes of the [auth_user]table before executing the createsuperuser command.

When I run the "python manage.py createsuperuser" command, an ODBC ERROR is displayed.

C:\Users\Myname\work>python manage.py createsuperuser  
Username (leave blank to use 'Myname'): DjangoAdmin  
Email address: DjangoAdmin@example.com  
Password:  
Password (again):  

*** [ODBC ERROR(2)] ***  
[CursorWrapper.execute(base.py)]  
sql=INSERT INTO [auth_user] ([password], [last_login], [is_superuser], [username], [first_name], [last_name], [email], [is_staff], [is_active], [date_joined]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  
params=( ... )  
('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] 'auth_user.last_login' )

Superuser created successfully.  

The screen will say "success", but in reality it has failed.
 
Immediately after creating the django system tables inside your Access database, you need to make some modifications.
Changes are required in columns [last_login], [first_name], and [last_name] of the [auth_user] table.
Please allow us to store "NULL values" as defined in database terms.
You can make it nullable by running the following VBScript:

Dim DAO  
Dim dbs  
'  
' HKEY_CLASSES_ROOT\DAO.DBEngine.120  
'  
Set DAO = WScript.CreateObject("DAO.DBEngine.120")  
Set dbs = DAO.OpenDatabase("C:\Users\Myname\work\MyDatabase.accdb")  

dbs.TableDefs("auth_user").Fields("last_login").Required = False  
dbs.TableDefs("auth_user").Fields("first_name").Required = False  
dbs.TableDefs("auth_user").Fields("last_name").Required = False  

dbs.Close  
Set dbs = Nothing  
Set DAO = Nothing  

 
 

Transaction statements cannot be executed.

SQL statements "SAVEPOINT" and "RELEASE SAVEPOINT" cannot be executed.
These commands are ignored.
Do not include any processing that requires a rollback.
 
 

There is a limit to the length of constraint names.

Constraint names can be up to 64 characters long.
Names longer than 64 characters can be truncated.
If the truncation is not performed, an error occurs.
This truncation function is not efficient enough to truncate all names longer than 64 characters. It's a lacking feature and needs to be improved.
If the ODBC error is due to a constraint name exceeding 64 characters, please let me know and I'll fix it.  
 

Install

pip install django-msaccess  

"pyodbc" also needs to be installed.  
 

Edit your settings.py file for your project.

change your DATABASES settings::

DATABASES = {  
    'default': {  
        'ENGINE': 'django-msaccess',  
        'ODBC': '{Microsoft Access Driver (*.mdb, *.accdb)}',  
        'PATH': 'This is the accdb file. Please enter the full path.',  
        'DEBUG': False,  
        'TRUNCATENAME': True,  
    },
}

The definition of
    'TRUNCATENAME':True
truncates the name. However, it is insufficient.

If you want to create an empty database file, you can use the following VBScript command:

Dim Cat  
Dim DBPath  
DBPath = "C:\work\MyNewDatabase.accdb"  
Set Cat = CreateObject("ADOX.Catalog")  
Cat.Create "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & ";"  
Set Cat = Nothing  

Use it to learn django.

Do not select Access as a production database.
Once you've finished learning django, it's time to switch to a full-fledged database.

Thank you for your interest in this software.

Lisence

This project is licensed under the MIT License, see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_msaccess-0.1.1.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_msaccess-0.1.1-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

File details

Details for the file django_msaccess-0.1.1.tar.gz.

File metadata

  • Download URL: django_msaccess-0.1.1.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for django_msaccess-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1dc30c5e6411612c1dc0001c0edc4ae560e0c4f2d9db8d54daa338dca5f07a0b
MD5 239766579f5bc22ea405b755743f7ceb
BLAKE2b-256 6b2029752a950a90d4dc7ec93f432d35297894662e58b847532f9be9185201d8

See more details on using hashes here.

File details

Details for the file django_msaccess-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_msaccess-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4112b25ff247ab39d57e449614c48099b0a3c136049d2032d5cd4422a2f149f3
MD5 d7f986c19998f9561cc532b9e7e8593f
BLAKE2b-256 01b82f9e5db94cfa3209dc42c478fb36986ab7b360177d0b31c34f21bdc039e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page