Firebird News

Wednesday, September 11, 2013

Django and Firebird support

I have started to read the django book and i could make it work with firebird without issues

Bellow are the instructions for Chapter 2 : Getting started

Install django using pip

pip install django

check django version from python console

>>> import django
>>> django.VERSION
(1, 5, x, 'final', 0)

pip install django-firebird

create a new project startproject wordpress_clone

cd wordpress_clone

python runserver

load in browser http://localhost:8000

Step 02 completed , we now should do the step 03

Chapter 3 is quite easy to read mainly hello world application here is the screenshot
after finising it (no modifications needed or related to firebird)

Chapter 04 is only related to templates so no modifications needed related to firebird.

So we reached chapter 05 the db and the The MTV Development Pattern (Beavis and Butthead pattern maybe )

In a way i like the Dumb pattern ViewController
Only the View and the Controller and The Model is in database anyway (triggers/rules/procedures and business logic)

I have created an empty database in /var/lib/firebird/2.5/data/firedjango.fdb
with flamerobin

Ok so the the shell worked with my firebird db config in

$python shell
>>> from django.db import connection
>>> cursor = connection.cursor()

So the next thing was to create the models and generate the db

$ python validate
$ python sqlall books

and here is the output

After that sync worked
$ python syncdb
import md5
Creating table books_publisher
Creating table books_book
Creating table books_author
Installing index for books.Book model

$ python shell
>>> from books.models import Publisher
>>> p1 = Publisher(name='Apress', address='2855 Telegraph Avenue',
... city='Berkeley', state_province='CA', country='U.S.A.',
... website='')
>>> p2 = Publisher(name="O'Reilly", address='10 Fawcett St.',
... city='Cambridge', state_province='MA', country='U.S.A.',
... website='')
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
[, ]

after i have added the _unicode method

$ python shell

>>> from books.models import Publisher
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
[<Publisher: Apress>, <Publisher: O'Reilly>]


Unknown said...

I have tried to use your changes with Firebird 1.5. I don't know which veresions of Firebird should work.
Apart form hard-coding in the base module I do not see how to specify that you do not wan to use the mx date routines.
When you use syncdb it put the table names and fieldnames in quotes which errors with my version of firebird.
If I can do anytong to help you please let me know.

Popa Adrian Marius said...

Hello , i have tested with latest firebird 2.1 stable (2.1.3) , i think is better to install that version to begin with

Unknown said...

Thanks for repling os quickly.
I have now installed that version, but still get this error with syncdb

kinterbasdb.DatabaseError: Execute query error. FB error No. -104
Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 14
"NAME" varchar(50) NOT NULL,
"CODENAME" varchar(100) NOT NULL,

I think it is because of the quotes?

Popa Adrian Marius said...

did you created the database with dialect 3

Maybe you need to create the database from scratch with flamerobin and to be done with new firebird 2.1.x server

also i guess you have installed the latest kinterbasdb 3.3.0

Unknown said...

I am using kinterbasdb3.2 which comes with the firebird on ubuntu.

How do you set the dialect in django settings?

Popa Adrian Marius said...

i didn't set any dialect i was just thinking that might be the issue

I guess you need to remove the old kinterbasdb
and install 3.3.0

Unknown said...

I can't make it work, I get django.core.exceptions.ImproperlyConfigured: 'firebird' isn't an available database backend. error, I use

-Linux Mint.
-django 1.7
-python 2.7
-firebird 2.5.
-django-firebird 1.6.4

I don't know if I have to do an other configuration in my computer, like put a path to firebird or something, Firebird works perfect alone and with python, but I have that error when I try to use it with Django.

'default': {
'ENGINE': 'firebird',
'NAME': '/var/lib/firebird/2.5/data/first_database.fdb',
'USER': 'SYSDBA', # Your db user
'PASSWORD': '*********', # db user password
'HOST': '', # Your host machine
'PORT': '3050', # If is empty, use default 3050

Popa Adrian Marius said...

you need to use django 1.6.x

django 1.7 support is in alpha state in the driver , you can test with git version
but i recommend to use 1.6.x with django 1.6.x