Hello and thank you very much for your answers.
stifan:
I thought that when you set migrate=False the content of db.py file was not
executed, but obviously I was wrong. So, if I put the CREATE INDEX in a
controller, the performance should be much better?
pallav:
Thank you very much, I will take this into account the next time I have
problems.
On Monday, April 14, 2014 8:05:10 AM UTC+2, pallav wrote:
>
> To use fake_migrate, first you have to revert your model definition to the
> old version (that matches the existing db), run the app. This will make
> web2py update the table definition file. Now, you can change your models
> and set fake_migrate to False, and migrate to True.
>
> On Sunday, April 13, 2014 5:49:17 PM UTC-4, Wonton wrote:
>>
>> Hello!
>>
>> I have a web2py application with a sqlite database. The structure of my
>> db.py file is something like this:
>>
>> db = DAL('sqlite://storage.sqlite', migrate=False)
>> ...
>> db.define_table('table1',
>> Field('field1'),
>> Field('field2'))
>> db.executesql('CREATE INDEX IF NOT EXISTS table1_field1 ON table1
>> (field1)')
>>
>> db.define_table('table2',
>> Field('field1'),
>> Field('field2'))
>> db.executesql('CREATE INDEX IF NOT EXISTS table2_field1 ON table2
>> (field1)')
>>
>> ...
>>
>> Each time I want to add a new table or a new field, I remove ",
>> migrate=False", make the change and, after it has been applied I add ",
>> migrate=False" again.
>> This has been working very well so far.
>>
>> Inside my database folder I have this files:
>> storage.sqlite
>> c8b1837fhj47blahblahblah_table1.table
>> c8b1837fhj47blahblahblah_table2.table
>>
>> Well, now my problem. Last time I made an update (I added a new table) in
>> my database, the migration was broken. I don't know why but I guess it was
>> probably because I removed accidentally the .table files and after restore
>> them maybe they were too old. I tried everything and finally the migration
>> worked and the database added the new table.
>>
>> Now my db.py file is something like this:
>>
>> db = DAL('sqlite://storage.sqlite', migrate=False)
>> ...
>> db.define_table('table1',
>> Field('field1'),
>> Field('field2'))
>> db.executesql('CREATE INDEX IF NOT EXISTS table1_field1 ON table1
>> (field1)')
>>
>> db.define_table('table2',
>> Field('field1'),
>> Field('field2'))
>> db.executesql('CREATE INDEX IF NOT EXISTS table2_field1 ON table2
>> (field1)')
>>
>> db.define_table('newtable',
>> Field('field1'))
>> db.executesql('CREATE INDEX IF NOT EXISTS newtable_field1 ON newtable
>> (field1)')
>>
>> ...
>>
>> but the first strange thing, in my database folder now I have this:
>> storage.sqlite
>> c8b1837fhj47blahblahblah_table1.table
>> c8b1837fhj47blahblahblah_table2.table
>> newtable.table
>>
>> Why newtable.table doesn't have the c8b1837fhj47blahblahblah part? Is
>> this important?
>>
>> The thing is that I need to add a new field to table1 table and I'm
>> getting errors and I don't know how to solve them.
>>
>> Just removing the ", migrate=False" part I get the error "newtable is
>> already defined" and the application fails.
>> I've tried to use db = DAL('sqlite://storage.sqlite', fake_migrate=True)and
>> have no errors. Then I add my new field but no changes are applied to
>> the database.
>>
>> What am i doing wrong? how could I fix this?
>>
>> Kind regards and thank you very much!
>>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.