*An easier solution for you could be this!*
Simply specify your created_by/modified_by as extra fields (which should 
side-step self-referencing probem).
I didn't test it, but it seems like a good idea to me. You can then use 
normal migrations etc.

    auth.settings.extra_fields['auth_user']= [

                     Field('is_active', 'boolean', default=True),
                     Field('created_on', 'datetime', default=request.now),
                     Field('created_by', 'integer', default=auth.user_id),
                     Field('modified_on', 'datetime', update=request.now),
                     Field('modified_by', 'integer', update=auth.user_id)

    ]

    auth.define_tables(... signature=False )

*Otherwise, in answer to your questions...*
migrate='asset_archive.table'
Personally, I do not specify the table definition name as the one given 
automatically by web2py is very good.  I just use migrate=True/False.
If you use migrate='asset_archive.table',  you are also specifying 
migrate=True

fake_migrate=True
This is used to recreate the .table file without touching your DB.
If you manually create and edit the fields in your DB,  you may wish to 
recreate the .table definition file (hence fake_migrate).

I am not sure how you are using the archiving etc,  but I do know this:  

   - you can manually create your own DB on-disk structure with whatever 
   triggers, indexes etc you require.
   - in web2py you can use define_table to create a web2py meta definition 
   (which must be compatible with what is on disk!)
   - you can use fake_migrate if you wish to create a .table definition 
   file (which will reflect your web2py define_table)
   - you can use migrate=False to prevent web2py from attempting to migrate 
   the physical DB on-disk structure

Using the above, the book explanation should make a little more sense.  

    





On Wednesday, 19 August 2020 09:43:42 UTC+1, Andrea Fae' wrote:

> Hello Villas, unfortunately other problems to this game...
> I used archiving, and so this type of table definitions
>
> db.define_table('asset_archive',
>                 Field('current_record', db.asset),
>                 db.asset,migrate='asset_archive.table')
>
> but I have the same problem regarding FOREIGN KEYS...no way to recreate 
> the tables.
>
> Do I have to give up the record archiving? Waht do you think?
>
> If you can, please can you explain the meaning of fake_migrate? I never 
> used and in the book is not very well explained. 
>
> Thank you
>
>
>
> Il giorno martedì 18 agosto 2020 22:38:50 UTC+2, villas ha scritto:
>>
>> I presume therefore that you need those fields.  This is the kind of 
>> thing I do to get things working.  Please forgive me if I've missed 
>> something.
>>
>>    - I would create those required fields manually in your database 
>>    (without the constraint that causes the problem).
>>    - Set auth.define_tables(migrate = True, fake_migrate=True)
>>    - Run the app.  This will create the .table definition file in the 
>>    databases dir.  You may have had to delete the old .table file.  If 
>>    necessary delete that.
>>    - Set auth.define_tables(migrate =False) again.
>>
>>
>> Sorry if this seems strange, but it is a work around solution.
>> I am hoping that someone will eventually fix this contraint problem in 
>> pyDal.
>>
>>
>> On Tuesday, 18 August 2020 20:51:57 UTC+1, Andrea Fae' wrote:
>>>
>>> Thank you Villas. I'm using option 2 and now I have the tables without 
>>> "created_by" and "modified_by".
>>> Now I will try to reset signature=true and see what will happen. If it 
>>> causes the same error I could add but they will not managed automatically 
>>> by web2py, or I'm wrong?
>>> What do you suggest?
>>> Thank you for your precious information.
>>>
>>> Il giorno lunedì 17 agosto 2020 14:24:25 UTC+2, villas ha scritto:
>>>>
>>>> Hi Andrea
>>>> I was pleased to see you are making progress with the DB connection etc.
>>>> I can see why mssql does not like the cascade from the same auth_user 
>>>> table.  This may be an issue which needs fixing...
>>>> To get things moving, and this might not be ideal, but I propose you 
>>>> consider either of these options:
>>>>
>>>>    1. Create manually your own tables without those contraints.  You 
>>>>    then set this:  auth.define_tables(... migrate=False ) so that 
>>>>    pyDal skips creation. 
>>>>    2. Do not include the signature fields with your auth.  
>>>>    auth.define_tables(... signature=False )
>>>>
>>>> Incidentally,  I use option 2 and I therefore do not benefit from the 
>>>> created and modified info,  but I could easily remedy this by adding the 
>>>> fields if I wished.
>>>> Hope this helps.
>>>>
>>>>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/434d0074-dd41-4b2b-9bdc-b135e7924dbco%40googlegroups.com.

Reply via email to