Friday, 29 May 2020

Wagtail: 'no such table' fix

When following the tutorial on setting up a blog in Wagtail I was getting the following issue when trying to add my Child blog page.

"no such table 'blog_blogindexpage' "

I'm not sure why but I couldn't fix just by changing my Models.py .  It didn't seem to be reading it all .  So I had to do the following 

1. Delete all my migrations in the blog/migrations table. 
2. Make sure the Class  BlogIndexPage 
 is in my 'models.py'
3. Run the following commands 

python manage.py makemigrations blog
python manage.py migrate

Wednesday, 27 May 2020

Django - Can't get Images to upload in custom Class based form




In my models.py I have the following

class Board(models.Model):
title = models.CharField(max_length=100)
image = models.ImageField(default='default-sb.jpg', upload_to='surfboard_pics')

The field is called in the Class based form 

class BoardCreateView(LoginRequiredMixin, CreateView):
model = Board
fields = ['title', 'image', 'length', 'width', 'volume', 'wave_range_start',
'wave_range_start', 'wave_range_end', 'shaper', 'year', 'make', 'notes']

At this point I can see the field.  The image upload works in Admin but not in my Form !



The fix was this .  In the template you need 'multipart enctype' to the Form tag.  Like this 

<form method="POST" enctype="multipart/form-data">

After adding this my form now works. 











Django - Make field not required

The solution for this was fairly simple but I had to search for a fair bit.  

Hopefully this will help someone else out. 

In your 'model.py' of the App you're working on you need to make this one simple change. 

I had 

width = models.CharField(max_length=5)


Which I added 

width = models.CharField(max_length=5, null=True, blank=True)

You'll also need to run the migrates again .  So 

python manage.py makemigrations YOURAPPNAME


Python manage.py migrate


You should now see that there's no asterix against this field on the form and that you can save a Null value. 

Wednesday, 9 October 2019

D8 custom entity reference field not working.

Drupal 8 custom entity reference field not working. 


On our site we've added a field that links to an Entity with the Entity Reference functionality.

When using is I just get a spinning circle and it never resolves.


The issue I had was that in the Schema of my custom Entity I had the 'label' set up incorrectly.


The file to change was in

my_custom_entity
     -- config
           -- schema
                   -- company_entity_type.schema.yml


company.company_entity_type.*:  type:  my_custom_entity  label: 'Type config'  mapping:    id:      type: string      label: 'ID'    label:      type: label      label: 'Label'    uuid:      type: string
Change this too .
company.company_entity_type.*:
type: my_custom_entity label: 'Type config' mapping: id: type: string label: 'ID' label: type: title label: 'Title' uuid: type: string

Tuesday, 24 September 2019

Drupal 8 - changes were detected in the entity type and field definitions. The % field needs to be updated.

While installing and Uninstalling Modules of Drupal 8 - using the Migrate tool I came across this issue.


Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.

AND THEN YOU GET A LIST

Something like




I have found two solutions for this , depending on whether this is a mismatched entity or field definition.   So I will list both .  Make sure you have a full backup of your site before you try these.


For Entity mismatches - what we need to do is cleanly remove our Modules, but cannot use the normal way as it gives us an error. 
Here's a lazy one liner.

drush eval "\$module_data = \Drupal::config('core.extension')->get('module'); unset(\$module_data[‘company’]); \Drupal::configFactory()->getEditable('core.extension')->set('module', \$module_data)->save()";

Here the module is called 'company' , you would swap that out for what you wish.php ../vendor/drupal/console/bin/drupal cache:rebuild
And when you've checked the site and are happy we should Export our new configuration 

php ../vendor/drush/drush/drush cex


FIX the FIELD DEFINITION 

That fixes all but the 'Name' field needs to be updated bug. 
For this I had to install this module 
https://www.drupal.org/project/devel_entity_updates
First of all I had to remove the Entity updates module .  You remove this by hand in the composer.json file .  And then run composer again
run composer

Now in the container Enable the module .  

drush pm:enable devel_entity_updates
And run the 'entup' command. 

drush entup


Here are some additional notes that I made while looking for this solution; that may help others find this article. 
I attempted to use updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);


What is the storage_definition for our field

How to find what the storage definition is for a field in Drupal 8. - that leads us here https://www.drupal.org/docs/8/api/entity-api/defining-and-using-content-entity-field-definitions

Drupal 8 get The field storage definition

Drupal 8 Errors found Entity / field definitions the % field needs to be updated hook_update_N getFieldStorageDefinition
Fix Drupal 8 The % field needs to be updated. hook_update_N issue

And then through that search I found that https://www.drupal.org/project/devel_entity_updates 


Saturday, 11 May 2019

Help finding a Part for the Toyota Alphard

This is a really simple tip but I think it worth noting as I found it difficult trying to find specific parts for my Toyota Alphard. 

This tip isn't just for the Toyota Alphard but it will be of help to owners of ANY other vehicle that can't find there parts on Ebay or a Car spares websites.

All you need to do is remember the work 'breaking'  !!  This may seem obvious to many but didn't occur to me ( a non mechanical person )

So go to Ebay and type in

'Toyota Alphard Breaking'  - or replace the car make with your own, and hopefully you should see some options of sellers who are scrapping a vehicle and selling off all the parts.

https://www.ebay.co.uk/sch/i.html?_trksid=toyota+alphard+breaking.TRS0&_nkw=toyota+alphard+breaking

Thursday, 2 May 2019

Toyota Alphard 2003- How to remove the tail light / indicator lights.



I couldn't find any videos or help on this for my exact module , so I thought I'd note it here.  With a picture.

Other similar Toyota models have a clip you push out.  And if you were to follow that as an example there is possibility that you'd break the housing

With my Toyota Alphard you remove the bolt and then push the housing towards the back of the vehicle. 

If you take a look at these images that should help .